cppx-core
is_empty.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
3 #include <cppx-core/language/syntax/macro-use.hpp> // CPPX_USE_STD
5 #include <cppx-core/language/types/Truth.hpp> // cppx::Truth
6 
7 #include <iterator> // std::(begin, end)
8 #include <type_traits> // std::(true_type, false_type)
9 #include <utility> // std::(declval)
10 
11 namespace cppx
12 {
13  CPPX_USE_STD( begin, end, declval, true_type, false_type );
14 
15  template< class Collection >
17  {
18  template< class C, int x = sizeof( declval<C>().empty() == true ) >
19  static auto test( const C& ) -> true_type;
20 
21  static auto test( ... ) -> false_type;
22 
23  public:
24  static constexpr Truth value = decltype(
25  test( declval<Collection>() )
26  )::value;
27  };
28 
29  template< class Collection >
31 
32  template< class Collection >
33  inline auto is_empty( const Collection& c )
34  -> Truth
35  {
36  if constexpr( has_method_empty_<Collection> )
37  {
38  return c.empty();
39  }
40  else
41  {
42  return begin( c ) == end( c );
43  }
44  }
45 
46  inline auto is_empty( const P_<const char> s ) -> Truth { return !*s; }
47  inline auto is_empty( const P_<const wchar_t> s ) -> Truth { return !*s; }
48  inline auto is_empty( const P_<const char16_t> s ) -> Truth { return !*s; }
49  inline auto is_empty( const P_<const char32_t> s ) -> Truth { return !*s; }
50 
51 } // namespace cppx
Some_type * P_
Creates a raw pointer type.
constexpr Truth has_method_empty_
Definition: is_empty.hpp:30
A drop-in replacement for bool without implicit conversion from/to types other than bool.
Definition: Truth.hpp:34
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.
auto is_empty(const Collection &c) -> Truth
Definition: is_empty.hpp:33
static constexpr Truth value
Definition: is_empty.hpp:24
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...