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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
10#define LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
11
12#include "src/__support/macros/attributes.h" // LIBC_INLINE
13
14#include <stddef.h>
15
16namespace LIBC_NAMESPACE {
17
18template <typename T> struct StrToNumResult {
19 T value;
20 int error;
21 ptrdiff_t parsed_len;
22
23 LIBC_INLINE constexpr StrToNumResult(T value)
24 : value(value), error(0), parsed_len(0) {}
25 LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len)
26 : value(value), error(0), parsed_len(parsed_len) {}
27 LIBC_INLINE constexpr StrToNumResult(T value, ptrdiff_t parsed_len, int error)
28 : value(value), error(error), parsed_len(parsed_len) {}
29
30 LIBC_INLINE constexpr bool has_error() { return error != 0; }
31
32 LIBC_INLINE constexpr operator T() { return value; }
33};
34} // namespace LIBC_NAMESPACE
35
36#endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
37

source code of libc/src/__support/str_to_num_result.h