brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 48c363c Raw
49 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9// -----------------------------------------------------------------------------10//                               **** WARNING ****11// This file is shared with libc++. You should also be careful when adding12// dependencies to this file, since it needs to build for all libc++ targets.13// -----------------------------------------------------------------------------14 15#ifndef LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H16#define LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H17 18#include "src/__support/macros/attributes.h" // LIBC_INLINE19#include "src/__support/macros/config.h"20 21#include <stddef.h>22 23namespace LIBC_NAMESPACE_DECL {24 25// -----------------------------------------------------------------------------26//                               **** WARNING ****27// This interface is shared with libc++, if you change this interface you need28// to update it in both libc and libc++.29// -----------------------------------------------------------------------------30template <typename T> struct StrToNumResult {31  T value;32  int error;33  ptrdiff_t parsed_len;34 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) {}41 42  LIBC_INLINE constexpr bool has_error() { return error != 0; }43 44  LIBC_INLINE constexpr operator T() { return value; }45};46} // namespace LIBC_NAMESPACE_DECL47 48#endif // LLVM_LIBC_SRC___SUPPORT_STR_TO_NUM_RESULT_H49