AuROXTL/Include/auROXTL/Utility/auTo.hpp

97 lines
2.6 KiB
C++

/***
Copyright (C) 2022-2024 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuTo.hpp
File: auTemplateMeta.hpp
Date: 2024-11-30
Date: 2023-01-18
Author: Reece
***/
#pragma once
#if defined(AU_LANG_CPP_14_)
template <class T>
using AuToValueType_t = typename T::value_type;
template <class T>
using AuToElementType_t = typename T::element_type;
template <class T>
using AuToIterator_t = typename T::iterator;
template <typename T>
static AuToIterator_t<T> AuToIterator(const T &a); // intended use case: `decltype(AuToIterator(myHashMap)) itr;`
template <typename T>
static AuToElementType_t<T> AuToElementType(const T &a);
template <typename T>
static AuToValueType_t<T> AuToValueType(const T &a);
#endif
#define AuToIterator_mt(T) typename T::iterator
#define AuToElementType_mt(T) typename T::element_type
#define AuToValueType_mt(T) typename T::value_type
namespace __audetail
{
template <class T>
struct AuHasElementType
{
template <class C> static AU_CONSTEXPR_14 AuTrueType Test(typename C::element_type *);
template <class C> static AU_CONSTEXPR_14 AuFalseType Test(...);
typedef decltype(Test<T>(0)) Type;
};
template <class T>
struct AuHasValueType
{
template <class C> static AU_CONSTEXPR_14 AuTrueType Test(typename C::value_type *);
template <class C> static AU_CONSTEXPR_14 AuFalseType Test(...);
typedef decltype(Test<T>(0)) Type;
};
template <class T>
struct AuHasIterator
{
template <class C> static AU_CONSTEXPR_14 AuTrueType Test(typename C::iterator *);
template <class C> static AU_CONSTEXPR_14 AuFalseType Test(...);
typedef decltype(Test<T>(0)) Type;
};
}
template <class T>
struct AuHasElementType : __audetail::AuHasElementType<T>::Type
{ };
template <class T>
struct AuHasValueType : __audetail::AuHasValueType<T>::Type
{ };
template <class T>
struct AuHasIterator : __audetail::AuHasIterator<T>::Type
{ };
#if defined(AU_LANG_CPP_14_)
template <class T, class U>
AUROXTL_CONSTEXPR_17 bool AuHasElementType_v = AuHasElementType<T>::kValue;
template <class T, class U>
AUROXTL_CONSTEXPR_17 bool AuHasValueType_v = AuHasValueType<T>::kValue;
template <class T, class U>
AUROXTL_CONSTEXPR_17 bool AuHasIterator_v = AuHasIterator<T>::kValue;
#endif
#define AuHasElementType_mv(T) (AuHasElementType<T>::kValue)
#define AuHasValueType_mv(T) (AuHasValueType<T>::kValue)
#define AuHasIterator_mv(T) (AuHasIterator<T>::kValue)