[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / str_to_num_result.h
blobcd0e24f6112d25bc38d306292f8a112fcebefeb0
1 //===-- A data structure for str_to_number to return ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SUPPORT_STR_TO_NUM_RESULT_H
10 #define LLVM_LIBC_SUPPORT_STR_TO_NUM_RESULT_H
12 #include <stddef.h>
14 namespace __llvm_libc {
16 template <typename T> struct StrToNumResult {
17 T value;
18 int error;
19 ptrdiff_t parsed_len;
21 constexpr StrToNumResult(T value) : value(value), error(0), parsed_len(0) {}
22 constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
23 : value(value), error(0), parsed_len(parsed_len) {}
24 constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
25 : value(value), error(error), parsed_len(parsed_len) {}
27 constexpr bool has_error() { return error != 0; }
29 constexpr operator T() { return value; }
31 } // namespace __llvm_libc
33 #endif // LLVM_LIBC_SUPPORT_STR_TO_NUM_RESULT_H