ugmisc 0.2
Miscellaneous C++ header library
Loading...
Searching...
No Matches
sfinae_helpers.hpp File Reference

Utility required by other ugmisc headers. More...

#include <limits>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Typedefs

template<class T>
using ugmisc::remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>
template<class T>
using ugmisc::plain_ref_t = std::remove_cv_t<T>&
template<class T, class R = T>
using ugmisc::uint_only
 Resolves to R if T is an unsigned integer.
template<class T, class R = T>
using ugmisc::modulo_uint_only
 Resolves to R if T is an unsigned integer with modulo arithmetic.
template<class T, class R = T>
using ugmisc::bitwise_uint_only
template<class T, class R = T>
using ugmisc::int_only

Functions

template<class T>
plain_ref_t< T > ugmisc::decl_plain_ref ()

Detailed Description

Utility required by other ugmisc headers.

The miscellaneous templates often want to be selected only when a type parameter is an integral type, or some similar condition. Since many of them use the same condition, it makes sense to make a special helper for that condition, which makes the declarations that use it a bit more legible.

Typedef Documentation

◆ bitwise_uint_only

template<class T, class R = T>
using ugmisc::bitwise_uint_only
Initial value:
std::enable_if_t<
std::numeric_limits<T>::is_integer
&& ( ! std::numeric_limits<T>::is_signed )
&& ( std::numeric_limits<T>::radix == 2 )
&& std::numeric_limits<T>::is_modulo
&& std::is_arithmetic_v<T>
&& is_bitwise<T>,
R
>

This type alias attempts to be valid only in cases where T supports bitwise operators, and where those operators work in the way you would normally expect.

In practice this could let some odd things slip through the net. If you create a type with a std::numeric_limits specialisation such that it claims to be an unsigned integer with a radix of 2, and it supports the |, &, ^, and ~ operators, but those operators don't do what someone would normally expect, then that could cause a problem.

◆ int_only

template<class T, class R = T>
using ugmisc::int_only
Initial value:
std::enable_if_t<
std::numeric_limits<T>::is_integer,
R
>

Resolves to R if T is an integer.

◆ modulo_uint_only

template<class T, class R = T>
using ugmisc::modulo_uint_only
Initial value:
std::enable_if_t<
std::numeric_limits<T>::is_integer
&& ( ! std::numeric_limits<T>::is_signed )
&& std::numeric_limits<T>::is_modulo
&& std::is_arithmetic_v<T>,
R
>

Resolves to R if T is an unsigned integer with modulo arithmetic.

◆ uint_only

template<class T, class R = T>
using ugmisc::uint_only
Initial value:
std::enable_if_t<
std::numeric_limits<T>::is_integer
&& ( ! std::numeric_limits<T>::is_signed ),
R
>

Resolves to R if T is an unsigned integer.