Functions | |
template<typename U > | |
static std::string | util::details::ToStringImpl< T, typename >::to_string (U &&obj) |
template<typename U > | |
static std::string | util::details::ToStringImpl< T, std::enable_if_t< util::is_basic_string_type_v< T > > >::to_string (U &&obj) |
template<typename U > | |
static std::string | util::details::ToStringImpl< T, std::enable_if_t< util::is_basic_string_view_type_v< T > > >::to_string (U &&obj) |
C++ standard library customization for user-defined classes. | |
template<typename T > | |
decltype(auto) constexpr | util::to_string (T &&obj) |
ADL-aware version of std::to_string . More... | |
template<typename T > | |
decltype(auto) constexpr | util::begin (T &&obj) |
ADL-aware version of std::begin . More... | |
template<typename T > | |
decltype(auto) constexpr | util::end (T &&obj) |
ADL-aware version of std::end . More... | |
template<typename T > | |
decltype(auto) constexpr | util::cbegin (T &&obj) |
ADL-aware version of std::cbegin . More... | |
template<typename T > | |
decltype(auto) constexpr | util::cend (T &&obj) |
ADL-aware version of std::cend . More... | |
template<typename T > | |
decltype(auto) constexpr | util::size (T &&obj) |
ADL-aware version of std::size . More... | |
template<typename T > | |
decltype(auto) constexpr | util::empty (T &&obj) |
ADL-aware version of std::empty . More... | |
template<std::size_t I, typename T > | |
decltype(auto) | util::get (T &&obj) |
There are a number of functions that are provided by C++ standard library for the data types and classes defined in the standard. It is often desirable to have your class react to these standard functions in a standard way, for example for a container to react to std::begin()
to return its begin()
iterator. While sometimes this is easy (for example std::begin()
calls begin()
member function if available), some other times that is not possible. In that case, since overloading of functions in the std
namespace is not allowed by C++, the usual pattern is to rely on the argument-dependent lookup (known as "ADL") to have the comnpiler find the overloaded function that is defined in the same namespace as any of the arguments. For example:
will look in the namespace where the type of obj
is defined (that is userns
) for a userns::to_string
, then will consider std::to_string
it self.
The utilities provided here provide a transparent way to do that, at the cost of a new header and some non-standard call. The equivalent call of the above would be:
std::hash
or std::numeric_limits
, specialization of classes in std
is allowed by the standard, so no particular trick is required. decltype(auto) constexpr util::begin | ( | T && | obj | ) |
ADL-aware version of std::begin
.
Definition at line 72 of file StdUtils.h.
decltype(auto) constexpr util::cbegin | ( | T && | obj | ) |
ADL-aware version of std::cbegin
.
Definition at line 82 of file StdUtils.h.
decltype(auto) constexpr util::cend | ( | T && | obj | ) |
ADL-aware version of std::cend
.
Definition at line 87 of file StdUtils.h.
decltype(auto) constexpr util::empty | ( | T && | obj | ) |
ADL-aware version of std::empty
.
Definition at line 97 of file StdUtils.h.
decltype(auto) constexpr util::end | ( | T && | obj | ) |
ADL-aware version of std::end
.
Definition at line 77 of file StdUtils.h.
decltype(auto) util::get | ( | T && | obj | ) |
Definition at line 107 of file StdUtils.h.
decltype(auto) constexpr util::size | ( | T && | obj | ) |
ADL-aware version of std::size
.
Definition at line 92 of file StdUtils.h.
decltype(auto) constexpr util::to_string | ( | T && | obj | ) |
ADL-aware version of std::to_string
.
|
inlinestatic |
Definition at line 127 of file StdUtils.h.
|
inlinestatic |
Definition at line 138 of file StdUtils.h.
|
inlinestatic |
Definition at line 149 of file StdUtils.h.