|
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:
- Note
- For customization of templates, like
std::hash
or std::numeric_limits
, specialization of classes in std
is allowed by the standard, so no particular trick is required.
template<typename T >
decltype(auto) constexpr util::begin |
( |
T && |
obj | ) |
|
ADL-aware version of std::begin
.
Definition at line 72 of file StdUtils.h.
auto begin(FixedBins< T, C > const &) noexcept
template<typename T >
decltype(auto) constexpr util::cbegin |
( |
T && |
obj | ) |
|
ADL-aware version of std::cbegin
.
Definition at line 82 of file StdUtils.h.
auto cbegin(FixedBins< T, C > const &) noexcept
template<typename T >
decltype(auto) constexpr util::cend |
( |
T && |
obj | ) |
|
ADL-aware version of std::cend
.
Definition at line 87 of file StdUtils.h.
auto cend(FixedBins< T, C > const &) noexcept
template<typename T >
decltype(auto) constexpr util::empty |
( |
T && |
obj | ) |
|
ADL-aware version of std::empty
.
Definition at line 97 of file StdUtils.h.
bool empty(FixedBins< T, C > const &) noexcept
template<typename T >
decltype(auto) constexpr util::end |
( |
T && |
obj | ) |
|
ADL-aware version of std::end
.
Definition at line 77 of file StdUtils.h.
78 {
using std::end;
return end(std::forward<T>(obj)); }
auto end(FixedBins< T, C > const &) noexcept
template<std::size_t I, typename T >
decltype(auto) util::get |
( |
T && |
obj | ) |
|
template<typename T >
decltype(auto) constexpr util::size |
( |
T && |
obj | ) |
|
ADL-aware version of std::size
.
Definition at line 92 of file StdUtils.h.
std::size_t size(FixedBins< T, C > const &) noexcept
template<typename T >
decltype(auto) constexpr util::to_string |
( |
T && |
obj | ) |
|
ADL-aware version of std::to_string
.
template<typename T , typename = void>
template<typename U >
Definition at line 127 of file StdUtils.h.
static std::string to_string(U &&obj)
std::string to_string(WindowPattern const &pattern)
template<typename T >
template<typename U >
template<typename T >
template<typename U >
Definition at line 149 of file StdUtils.h.
149 {
return { obj.begin(), obj.end() }; }