MSVC SFINAE bug fixes

This commit is contained in:
Jack Andersen 2018-02-26 20:02:24 -10:00
parent 2381e65d0d
commit 2b41d0234a
8 changed files with 39 additions and 39 deletions

View File

@ -237,6 +237,10 @@ install(EXPORT AthenaTargets DESTINATION ${INSTALL_CMAKE_DIR} COMPONENT athena)
if(NOT GEKKO)
add_subdirectory(atdna)
# Test target
atdna(atdna_test.cpp atdna/test.hpp)
add_executable(atdna-test atdna/test.cpp atdna_test.cpp atdna/test.hpp)
target_link_libraries(atdna-test athena-core athena-libyaml)
endif()
#########

View File

@ -234,9 +234,4 @@ macro(atdna out)
endif()
endmacro()
# Test target
atdna(atdna_test.cpp test.hpp)
add_executable(atdna-test test.cpp atdna_test.cpp test.hpp)
target_link_libraries(atdna-test athena-core athena-libyaml)
endif()

View File

@ -6,6 +6,7 @@
#include "YAMLDocReader.hpp"
#include "YAMLDocWriter.hpp"
#include "ChecksumsLiterals.hpp"
#include <type_traits>
namespace athena::io
{
@ -65,16 +66,15 @@ enum class PropType
};
template <class T>
static inline constexpr bool __IsPODType()
{
return std::is_arithmetic_v<T> ||
std::is_convertible_v<T&, atVec2f&> ||
std::is_convertible_v<T&, atVec3f&> ||
std::is_convertible_v<T&, atVec4f&> ||
std::is_convertible_v<T&, atVec2d&> ||
std::is_convertible_v<T&, atVec3d&> ||
std::is_convertible_v<T&, atVec4d&>;
}
using __IsPODType = typename std::disjunction<std::is_arithmetic<T>,
std::is_convertible<T&, atVec2f&>,
std::is_convertible<T&, atVec3f&>,
std::is_convertible<T&, atVec4f&>,
std::is_convertible<T&, atVec2d&>,
std::is_convertible<T&, atVec3d&>,
std::is_convertible<T&, atVec4d&>>;
template <class T>
inline constexpr bool __IsPODType_v = __IsPODType<T>::value;
template <class T>
using __CastPODType = typename std::conditional_t<std::is_convertible_v<T&, atVec2f&>, atVec2f,
@ -139,7 +139,7 @@ struct BinarySize
BinarySize<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType<T>()>
static typename std::enable_if_t<__IsPODType_v<T>>
Do(const PropId& id, T& var, StreamT& s)
{
if (PropOp != PropType::None)
@ -151,7 +151,7 @@ struct BinarySize
BinarySize<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None>
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp != PropType::None>
Do(const PropId& id, T& var, StreamT& s)
{
/* Accessed via Enumerate, header */
@ -159,7 +159,7 @@ struct BinarySize
var.template Enumerate<BinarySize<PropOp>>(s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None>
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp == PropType::None>
Do(const PropId& id, T& var, StreamT& s)
{
var.template Enumerate<BinarySize<PropType::None>>(s);
@ -347,7 +347,7 @@ struct Read
Read<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType<T>()>
static typename std::enable_if_t<__IsPODType_v<T>>
Do(const PropId& id, T& var, StreamT& r)
{
using CastT = __CastPODType<T>;
@ -398,7 +398,7 @@ struct Read
{
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < count; ++i)
for (size_t i = 0; i < static_cast<size_t>(count); ++i)
{
vector.emplace_back();
Read<PropOp>::Do<T, DNAE>(id, vector.back(), r);
@ -518,7 +518,7 @@ struct Write
Write<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType<T>()>
static typename std::enable_if_t<__IsPODType_v<T>>
Do(const PropId& id, T& var, StreamT& w)
{
using CastT = __CastPODType<T>;
@ -679,14 +679,14 @@ struct ReadYaml
ReadYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType<T>()>
static typename std::enable_if_t<__IsPODType_v<T>>
Do(const PropId& id, T& var, StreamT& r)
{
using CastT = __CastPODType<T>;
ReadYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>()>
static typename std::enable_if_t<__IsDNARecord_v<T>>
Do(const PropId& id, T& var, StreamT& r)
{
if (auto rec = r.enterSubRecord(id.name))
@ -818,14 +818,14 @@ struct WriteYaml
WriteYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType<T>()>
static typename std::enable_if_t<__IsPODType_v<T>>
Do(const PropId& id, T& var, StreamT& w)
{
using CastT = __CastPODType<T>;
WriteYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>()>
static typename std::enable_if_t<__IsDNARecord_v<T>>
Do(const PropId& id, T& var, StreamT& w)
{
if (auto rec = w.enterSubRecord(id.name))

View File

@ -12,14 +12,14 @@ namespace athena::io
template <class T>
static inline const char* __GetDNAName(const T& dna,
typename std::enable_if_t<athena::io::__IsDNAVRecord<T>()>* = 0)
typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0)
{
return dna.DNATypeV();
}
template <class T>
static inline const char* __GetDNAName(const T& dna,
typename std::enable_if_t<!athena::io::__IsDNAVRecord<T>()>* = 0)
typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0)
{
return dna.DNAType();
}

View File

@ -146,17 +146,16 @@ template <Endian DNAE>
struct DNAV;
template <class T>
static inline constexpr bool __IsDNARecord()
{
return std::is_base_of_v<DNA<Endian::Big>, T> ||
std::is_base_of_v<DNA<Endian::Little>, T>;
}
using __IsDNARecord = typename std::disjunction<std::is_base_of<DNA<Endian::Big>, T>,
std::is_base_of<DNA<Endian::Little>, T>>;
template <class T>
static inline constexpr bool __IsDNAVRecord()
{
return std::is_base_of_v<DNAV<Endian::Big>, T> ||
std::is_base_of_v<DNAV<Endian::Little>, T>;
}
inline constexpr bool __IsDNARecord_v = __IsDNARecord<T>::value;
template <class T>
using __IsDNAVRecord = typename std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>,
std::is_base_of<DNAV<Endian::Little>, T>>;
template <class T>
inline constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
}
} // Athena

View File

@ -9,6 +9,8 @@
#include <yaml.h>
#include <utf8proc.h>
#include <vector>
#include <memory>
#include <functional>
#include "Global.hpp"
namespace athena::io

View File

@ -49,7 +49,7 @@ public:
template <class T>
void enumerate(const char* name, T& record,
typename std::enable_if_t<__IsDNARecord<T>()>* = 0)
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
{
if (auto rec = enterSubRecord(name))
record.read(*this);

View File

@ -40,7 +40,7 @@ public:
template <class T>
void enumerate(const char* name, T& record,
typename std::enable_if_t<__IsDNARecord<T>()>* = 0)
typename std::enable_if_t<__IsDNARecord_v<T>>* = 0)
{
if (auto rec = enterSubRecord(name))
record.write(*this);