@@ -22,27 +22,34 @@ FOUR_C_NAMESPACE_OPEN
2222// into this special templates file.
2323namespace Core ::IO::Internal::InputParameterContainerImplementation
2424{
25- // Default printer if not printable.
2625 template <typename T>
27- struct PrintHelper
28- {
29- void operator ()(std::ostream& os, const std::any& data) { os << " <not printable> " ; }
26+ concept StreamInsertable = requires (std::ostream& os, const std::any& data) {
27+ { os << std::any_cast<T>(data) };
3028 };
3129
30+ // Helper struct to print the data in the container.
3231 template <typename T>
33- concept StreamInsertable = requires (std::ostream& os, const T& t) { os << t; };
34-
35- // Specialization for stream insert.
36- template <StreamInsertable T>
37- struct PrintHelper <T>
32+ struct PrintHelper
3833 {
39- void operator ()(std::ostream& os, const std::any& data) { os << std::any_cast<T>(data) << " " ; }
34+ void operator ()(std::ostream& os, const std::any& data) const
35+ {
36+ if constexpr (StreamInsertable<std::remove_reference_t <T>> || std::is_enum_v<T>)
37+ {
38+ using EnumTools::operator <<;
39+ os << std::any_cast<T>(data) << " " ;
40+ }
41+ else
42+ {
43+ os << " <not printable> " ;
44+ }
45+ }
4046 };
4147
42- template <StreamInsertable T>
48+ // Specialization for std::optional.
49+ template <SupportedType T>
4350 struct PrintHelper <std::optional<T>>
4451 {
45- void operator ()(std::ostream& os, const std::any& data)
52+ void operator ()(std::ostream& os, const std::any& data) const
4653 {
4754 auto val = std::any_cast<std::optional<T>>(data);
4855 if (val.has_value ())
@@ -53,10 +60,10 @@ namespace Core::IO::Internal::InputParameterContainerImplementation
5360 };
5461
5562 // Specialization for vectors.
56- template <typename T>
63+ template <SupportedType T>
5764 struct PrintHelper <std::vector<T>>
5865 {
59- void operator ()(std::ostream& os, const std::any& data)
66+ void operator ()(std::ostream& os, const std::any& data) const
6067 {
6168 FOUR_C_ASSERT (typeid (std::vector<T>) == data.type (), " Implementation error." );
6269 const auto & vec = std::any_cast<std::vector<T>>(data);
@@ -68,10 +75,10 @@ namespace Core::IO::Internal::InputParameterContainerImplementation
6875 };
6976
7077 // Specialization for maps.
71- template <typename Key, typename Value>
78+ template <typename Key, SupportedType Value>
7279 struct PrintHelper <std::map<Key, Value>>
7380 {
74- void operator ()(std::ostream& os, const std::any& data)
81+ void operator ()(std::ostream& os, const std::any& data) const
7582 {
7683 FOUR_C_ASSERT (typeid (std::map<Key, Value>) == data.type (), " Implementation error." );
7784 const auto & map = std::any_cast<std::map<Key, Value>>(data);
0 commit comments