Commit b9b95dd1 authored by Lukas Tietze's avatar Lukas Tietze

Mehr TypeTraits

parent 6d946954
#pragma once
#include <type_traits>
#include <iterator>
namespace lib
{
/**
* @brief type trait um zu prüfen ob ein Typ ein Iterator ist.
*
* @tparam T Der zu prüfende Typ.
*/
template <typename T, typename = void>
struct is_iterator
{
static constexpr bool value = false;
};
/**
* @brief type trait um zu prüfen ob ein Typ ein Iterator ist.
*
* @tparam T Der zu prüfende Typ.
*/
template <typename T>
struct is_iterator<T, typename std::enable_if<!std::is_same<typename std::iterator_traits<T>::value_type, void>::value>::type>
{
static constexpr bool value = true;
};
/**
* @brief type trait um zu prüfen ob ein Typ ein Iterator ist.
*
* @tparam T Der zu prüfende Typ.
*/
template <typename T>
static constexpr auto is_iterator_v = lib::is_iterator<T>::value;
// ---------------------------------------------------------------------------------------------------------------
// is_iterable
// ---------------------------------------------------------------------------------------------------------------
template <typename T, typename = void>
struct is_iterable
{
static constexpr bool value = false;
};
template <typename T>
struct is_iterable<T, typename std::enable_if<
std::is_same<
decltype(std::cbegin(std::declval<T>())),
decltype(std::cend(std::declval<T>()))>::value &&
lib::is_iterator<decltype(std::cbegin(std::declval<T>()))>::value &&
lib::is_iterator<decltype(std::cend(std::declval<T>()))>::value>::type>
{
static constexpr bool value = true;
};
template <typename T>
static constexpr auto is_iterable_v = lib::is_iterable<T>::value;
// ---------------------------------------------------------------------------------------------------------------
// is_contiguos_memory
// ---------------------------------------------------------------------------------------------------------------
template <typename T, typename = void>
struct is_contiguos_memory
{
static constexpr bool value = false;
};
template <typename T>
struct is_contiguos_memory<
T,
typename std::enable_if<
std::is_pointer<decltype(std::declval<T>().data())>::value &&
std::is_integral<decltype(std::declval<std::vector<int>>().size())>::value>::type>
{
static constexpr bool value = true;
};
template <typename T>
static constexpr auto is_contiguos_memory_v = is_contiguos_memory<T>::value;
} // namespace lib
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment