1 //===-- A data structure for str_to_number to return ------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // -----------------------------------------------------------------------------
11 // This file is shared with libc++. You should also be careful when adding
12 // dependencies to this file, since it needs to build for all libc++ targets.
13 // -----------------------------------------------------------------------------
15 #ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
16 #define LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H
18 #include "src/__support/macros/attributes.h" // LIBC_INLINE
19 #include "src/__support/macros/config.h"
23 namespace LIBC_NAMESPACE_DECL
{
25 // -----------------------------------------------------------------------------
27 // This interface is shared with libc++, if you change this interface you need
28 // to update it in both libc and libc++.
29 // -----------------------------------------------------------------------------
30 template <typename T
> struct StrToNumResult
{
35 LIBC_INLINE
constexpr StrToNumResult(T value
)
36 : value(value
), error(0), parsed_len(0) {}
37 LIBC_INLINE
constexpr StrToNumResult(T value
, ptrdiff_t parsed_len
)
38 : value(value
), error(0), parsed_len(parsed_len
) {}
39 LIBC_INLINE
constexpr StrToNumResult(T value
, ptrdiff_t parsed_len
, int error
)
40 : value(value
), error(error
), parsed_len(parsed_len
) {}
42 LIBC_INLINE
constexpr bool has_error() { return error
!= 0; }
44 LIBC_INLINE
constexpr operator T() { return value
; }
46 } // namespace LIBC_NAMESPACE_DECL
48 #endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H