Logo ROOT   6.12/07
Reference Guide
RStringView.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Author: Philippe Canal, March 2015
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef RStringView_H
13 #define RStringView_H
14 
15 #include "RConfigure.h"
16 
17 #ifdef R__HAS_STD_STRING_VIEW
18 
19 #include <string_view>
20 
21 #else
22 
23 # if defined(R__HAS_STD_EXPERIMENTAL_STRING_VIEW)
24 # include <experimental/string_view>
25 # else
27 # endif
28 
29 namespace std {
30 
31  template<class _CharT, class _Traits = std::char_traits<_CharT> >
32  using basic_string_view = ::std::experimental::basic_string_view<_CharT,_Traits>;
33 
34  // basic_string_view typedef names
39 
40 // template<class _CharT, class _Traits = std::char_traits<_CharT> >
41 // basic_string_view<_CharT,_Traits>
42 // &operator=(basic_string_view<_CharT,_Traits> &lhs, const TString &rsh) {
43 // *lhs = basic_string_view<_CharT,_Traits>(rsh);
44 // return *lhs;
45 // }
46 
47 #ifndef R__HAS_STOD_STRING_VIEW
48  inline double stod(std::string_view str, size_t *pos)
49  {
50  return std::stod(std::string(str.data(), str.size()),pos);
51  }
52 #endif
53 
54 }
55 
56 #endif // ifdef else R__HAS_STD_STRING_VIEW
57 
58 namespace ROOT {
59 namespace Internal {
60  class TStringView {
61  const char *fData{nullptr};
62  size_t fLength{0};
63 
64  public:
65  explicit TStringView(const char *cstr, size_t len) : fData(cstr), fLength(len) {}
66 
67  operator std::string_view() const { return std::string_view(fData,fLength); }
68  };
69 } // namespace Internal
70 } // namespace ROOT
71 #endif // RStringView_H
basic_string_view< char > string_view
Definition: RStringView.h:35
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TStringView(const char *cstr, size_t len)
Definition: RStringView.h:65
STL namespace.
double stod(std::string_view str, size_t *pos)
Definition: RStringView.h:48
basic_string_view< char > string_view
basic_string_view< wchar_t > wstring_view
basic_string_view< char32_t > u32string_view
basic_string_view< char16_t > u16string_view