Comment.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_Comment_h
2 #define fhiclcpp_types_Comment_h
3 
4 // There are two ways to initialize a fhicl::Comment:
5 //
6 // fhicl::Comment{"Hello world."} ==> Argument is char const*
7 // fhicl::Comment{std::to_string(47)} ==> Argument is std::string
8 //
9 // Technical comments:
10 //
11 // Specifying a Comment constructor that takes an std::string can
12 // yield ambiguities for Sequence objects, which support
13 // initialization with default values via an std::initializer_list.
14 // To get around this issue, a layer of indirection is added to the
15 // Comment c'tor--the comment_detail::ArgWrapper, which supports
16 // implicit conversion of a 'char const*' or 'std::string' argument
17 // to itself. The extra layer introduces an additional conversion
18 // required for a Sequence object, making it disfavored in overload
19 // resolution.
20 
21 #include <string>
22 
23 namespace fhicl {
24 
25  namespace comment_detail {
26  struct ArgWrapper {
27  ArgWrapper(char const* arg) : value{arg} {}
28  ArgWrapper(std::string const& arg) : value{arg} {}
30  };
31  }
32 
33  struct Comment {
35  : value{wrapper.value}
36  {}
38  };
39 }
40 
41 #endif /* fhiclcpp_types_Comment_h */
42 
43 // Local variables:
44 // mode: c++
45 // End:
std::string string
Definition: nybbler.cc:12
ArgWrapper(std::string const &arg)
Definition: Comment.h:28
ArgWrapper(char const *arg)
Definition: Comment.h:27
Comment(comment_detail::ArgWrapper const &wrapper)
Definition: Comment.h:34
std::string value
Definition: Comment.h:37