arsenalgear-cpp
A library containing general purpose C++ utils.
type.hpp
Go to the documentation of this file.
1 //====================================================
2 // File data
3 //====================================================
11 //====================================================
12 // Preprocessor settings
13 //====================================================
14 #pragma once
15 #ifndef ARSENALGEAR_TYPE_HPP
16 #define ARSENALGEAR_TYPE_HPP
17 
18 //====================================================
19 // Headers
20 //====================================================
21 
22 // STD headers
23 #include <type_traits>
24 #include <string>
25 #include <string_view>
26 #include <iostream>
27 #include <typeinfo>
28 
29 namespace agr
30  {
31  //====================================================
32  // Structs
33  //====================================================
34 
35  // is_streamable
43  template<typename S, typename T, typename = void>
44  struct is_streamable: std::false_type {};
45 
46  // is_streamable specialization
47  template<typename S, typename T>
48  struct is_streamable <S, T, std::void_t<decltype( std::declval <S&>() <<std::declval<T>() ) > >: std::true_type {};
49 
50  //====================================================
51  // Functions
52  //====================================================
53 
54  // is_pointer_to_const_char (first overload)
63  template <typename T, std::size_t N>
64  constexpr bool is_pointer_to_const_char( T(&)[N] )
65  {
66  return std::is_same_v <const char, T>;
67  }
68 
69  // is_pointer_to_const_char (second overload)
77  template<typename T>
78  constexpr bool is_pointer_to_const_char( T&& )
79  {
80  return std::is_same_v <const char *, T>;
81  }
82 
83  // is_str
92  template <class T>
93  constexpr bool is_str( const T& obj )
94  {
95  return is_pointer_to_const_char( obj ) || std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>;
96  }
97 
98  // is_any
107  template <typename Kind, typename... Kinds>
108  bool is_any()
109  {
110  if constexpr ( ( std::is_same_v <Kind, Kinds> || ... ) )
111  {
112  return true;
113  }
114  return false;
115  }
116  }
117 
118 #endif
Definition: stream.cpp:22
Struct used to check if a type is a streamable or not, i.e. it has operator << overload or not.
Definition: type.hpp:44