Version: SMASH-3.2.2
traits.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2024-2025
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_TRAITS_H_
11 #define SRC_INCLUDE_SMASH_TRAITS_H_
12 
13 #include <sstream>
14 #include <string>
15 #include <type_traits>
16 #include <vector>
17 
18 #include "stringify.h"
19 
20 namespace smash {
21 
30 template <typename S, typename T, typename = void>
31 struct is_writable_to_stream : std::false_type {};
32 
39 template <typename S, typename T>
41  S, T, std::void_t<decltype(std::declval<S&>() << std::declval<T>())>>
42  : std::true_type {};
43 
47 template <typename S, typename T>
48 inline constexpr bool is_writable_to_stream_v =
49  is_writable_to_stream<S, T>::value;
50 
59 template <typename T, typename Enable = void>
60 struct has_to_string : std::false_type {};
61 
78 template <typename T>
79 struct has_to_string<T,
80  std::void_t<decltype(smash::to_string(std::declval<T>()))>>
81  : std::is_same<decltype(smash::to_string(std::declval<T>())), std::string> {
82 };
83 
93 template <std::size_t N>
94 struct has_to_string<std::bitset<N>, std::void_t<decltype(smash::to_string(
95  std::declval<std::bitset<N>>()))>>
96  : std::is_same<decltype(smash::to_string(std::declval<std::bitset<N>>())),
97  std::vector<std::string>> {};
98 
102 template <typename T>
103 inline constexpr bool has_to_string_v = has_to_string<T>::value;
104 
105 } // namespace smash
106 
107 #endif // SRC_INCLUDE_SMASH_TRAITS_H_
Definition: action.h:24
#define S(x, n)
Definition: sha256.cc:54
Type trait to infer if a type can be streamed via the << operator.
Definition: traits.h:31