|
@ -8,6 +8,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace gp{ |
|
|
namespace gp{ |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Picks either of the types depending on the condition |
|
|
|
|
|
* |
|
|
|
|
|
* @tparam cond the condition |
|
|
|
|
|
* @tparam T the type picked when the condition is true |
|
|
|
|
|
* @tparam U the type picked when the condition is false |
|
|
|
|
|
*/ |
|
|
template<bool cond, typename T, typename U> |
|
|
template<bool cond, typename T, typename U> |
|
|
struct either |
|
|
struct either |
|
|
{ |
|
|
{ |
|
@ -25,6 +32,9 @@ namespace gp{ |
|
|
typedef U type; |
|
|
typedef U type; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Checks if the provided booleans are all true at compile time |
|
|
|
|
|
*/ |
|
|
template<bool first, bool ...list> |
|
|
template<bool first, bool ...list> |
|
|
struct constexpr_all_of |
|
|
struct constexpr_all_of |
|
|
{ |
|
|
{ |
|
@ -37,6 +47,9 @@ namespace gp{ |
|
|
static constexpr bool value = first; |
|
|
static constexpr bool value = first; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Checks if at least one of the provided booleans is true at compile time |
|
|
|
|
|
*/ |
|
|
template<bool first, bool ...list> |
|
|
template<bool first, bool ...list> |
|
|
struct constexpr_any_of |
|
|
struct constexpr_any_of |
|
|
{ |
|
|
{ |
|
@ -49,6 +62,13 @@ namespace gp{ |
|
|
static constexpr bool value = first; |
|
|
static constexpr bool value = first; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Checks if the provided type has a compile time defined size |
|
|
|
|
|
* |
|
|
|
|
|
* @tparam T the tested type |
|
|
|
|
|
* @return true if it has a defined size |
|
|
|
|
|
* @return false if its size may change due to inheritance or other factors |
|
|
|
|
|
*/ |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
constexpr bool is_fixed_size() |
|
|
constexpr bool is_fixed_size() |
|
|
{ |
|
|
{ |
|
@ -56,6 +76,9 @@ namespace gp{ |
|
|
|| std::is_fundamental<T>::value; |
|
|
|| std::is_fundamental<T>::value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Checks if the provided typelist is all of fixed size |
|
|
|
|
|
*/ |
|
|
template<typename T, typename ...rest> |
|
|
template<typename T, typename ...rest> |
|
|
struct all_of_fixed_size |
|
|
struct all_of_fixed_size |
|
|
{ |
|
|
{ |
|
@ -68,6 +91,11 @@ namespace gp{ |
|
|
static constexpr bool value = is_fixed_size<T>(); |
|
|
static constexpr bool value = is_fixed_size<T>(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Checks if the provided list contains the provided class |
|
|
|
|
|
* |
|
|
|
|
|
* @tparam Univ the class to look for |
|
|
|
|
|
*/ |
|
|
template<typename Univ, typename T, typename ...rest> |
|
|
template<typename Univ, typename T, typename ...rest> |
|
|
struct list_contains_class |
|
|
struct list_contains_class |
|
|
{ |
|
|
{ |
|
@ -82,6 +110,11 @@ namespace gp{ |
|
|
static constexpr bool value = std::is_same<T, Univ>::value; |
|
|
static constexpr bool value = std::is_same<T, Univ>::value; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief gives the index of Univ from the end of the argument list |
|
|
|
|
|
* |
|
|
|
|
|
* @tparam Univ The type to look for |
|
|
|
|
|
*/ |
|
|
template<typename Univ, typename T, typename ...rest> |
|
|
template<typename Univ, typename T, typename ...rest> |
|
|
struct r_index_of |
|
|
struct r_index_of |
|
|
{ |
|
|
{ |
|
@ -94,6 +127,12 @@ namespace gp{ |
|
|
static constexpr std::size_t value = std::is_same<T, Univ>::value ? 0 : std::numeric_limits<std::size_t>::max(); |
|
|
static constexpr std::size_t value = std::is_same<T, Univ>::value ? 0 : std::numeric_limits<std::size_t>::max(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief gives the type of the idx value from the end of the argument list |
|
|
|
|
|
* |
|
|
|
|
|
* @tparam idx The index to return the type of |
|
|
|
|
|
*/ |
|
|
template<size_t idx, typename T, typename ...rest> |
|
|
template<size_t idx, typename T, typename ...rest> |
|
|
struct r_index_at |
|
|
struct r_index_at |
|
|
{ |
|
|
{ |
|
@ -105,11 +144,19 @@ namespace gp{ |
|
|
>::type; |
|
|
>::type; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief extracts the first type of the list |
|
|
|
|
|
*/ |
|
|
template<typename U, typename ...rest> |
|
|
template<typename U, typename ...rest> |
|
|
struct first_of { |
|
|
struct first_of { |
|
|
using type = U; |
|
|
using type = U; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief gives the size of the largest element in the provided list |
|
|
|
|
|
* |
|
|
|
|
|
* @return constexpr std::size_t equal to the largest size of all |
|
|
|
|
|
*/ |
|
|
template<typename T, typename U, typename ...rest> |
|
|
template<typename T, typename U, typename ...rest> |
|
|
constexpr std::size_t max_size() |
|
|
constexpr std::size_t max_size() |
|
|
{ |
|
|
{ |
|
@ -129,6 +176,9 @@ namespace gp{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief remove reference state from the provided type |
|
|
|
|
|
*/ |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
struct remove_reference |
|
|
struct remove_reference |
|
|
{ |
|
|
{ |
|
@ -147,6 +197,9 @@ namespace gp{ |
|
|
using type = T; |
|
|
using type = T; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Has a value of true if the provided type has a size() function member |
|
|
|
|
|
*/ |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
struct has_size_interface |
|
|
struct has_size_interface |
|
|
{ |
|
|
{ |
|
@ -164,6 +217,9 @@ namespace gp{ |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Has a value of true if the provided type has a begin() function member |
|
|
|
|
|
*/ |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
struct has_begin_interface |
|
|
struct has_begin_interface |
|
|
{ |
|
|
{ |
|
@ -181,6 +237,9 @@ namespace gp{ |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Has a value of true if the provided type has a end() function member |
|
|
|
|
|
*/ |
|
|
template<typename T> |
|
|
template<typename T> |
|
|
struct has_end_interface |
|
|
struct has_end_interface |
|
|
{ |
|
|
{ |
|
@ -198,6 +257,8 @@ namespace gp{ |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
static constexpr bool value = std::is_same<yes,decltype(test<T>(nullptr))>::value; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Replace those with concepts
|
|
|
|
|
|
|
|
|
template<typename T> |
|
|
template<typename T> |
|
|
using has_range_interface = constexpr_all_of<has_begin_interface<T>::value,has_end_interface<T>::value>; |
|
|
using has_range_interface = constexpr_all_of<has_begin_interface<T>::value,has_end_interface<T>::value>; |
|
|
|
|
|
|
|
|