LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
maybe_insert.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_maybe_insert_h
2 #define fhiclcpp_types_detail_maybe_insert_h
3 
4 #include <ostream>
5 #include <sstream>
6 #include <string>
7 #include <utility>
8 
9 namespace fhicl::detail {
10  template <typename T>
12  decltype(std::declval<std::ostream&>() << std::declval<T const&>());
13 
14  template <typename T, typename = void>
15  constexpr bool has_insertion_operator{false};
16 
17  template <typename T>
18  constexpr bool
19  has_insertion_operator<T, std::void_t<insertion_expression_t<T>>>{true};
20 
21  template <typename T>
22  std::string
23  maybe_insert(T const& t)
24  {
25  if constexpr (has_insertion_operator<T>) {
26  std::ostringstream os;
27  os << " with a default value of:\n"
28  << " " << t;
29  return os.str();
30  }
31  return " A default value is present, but it cannot be\n"
32  " printed out since no 'operator<<' overload has\n"
33  " been provided for the above type.";
34  }
35 }
36 
37 #endif /* fhiclcpp_types_detail_maybe_insert_h */
38 
39 // Local variables:
40 // mode: c++
41 // End:
decltype(std::declval< std::ostream & >()<< std::declval< T const & >()) insertion_expression_t
Definition: maybe_insert.h:12
std::string maybe_insert(T const &t)
Definition: maybe_insert.h:23
constexpr bool has_insertion_operator
Definition: maybe_insert.h:15