Skip to content

Commit c65f05d

Browse files
authored
Merge pull request #31 from ReflectCxx/release-2.0.CleanSfinae
replaced SFINAE with if constexpr(), cleaner approach
2 parents ba6959d + 2bae225 commit c65f05d

File tree

3 files changed

+10
-61
lines changed

3 files changed

+10
-61
lines changed

ReflectionTemplateLib/builder/inc/ConstructorBuilder.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace rtl {
66

77
namespace builder
88
{
9-
template<class _recordType = void, class ..._ctorSignature>
9+
template<class _recordType, class ..._ctorSignature>
1010
class ConstructorBuilder
1111
{
1212
const std::string& m_record;
@@ -23,32 +23,4 @@ namespace rtl {
2323
inline constexpr const access::Function build() const;
2424
};
2525
}
26-
27-
28-
namespace builder
29-
{
30-
template<>
31-
class ConstructorBuilder<>
32-
{
33-
public:
34-
35-
template<class _recordType, class ..._signature>
36-
static constexpr const ConstructorBuilder<_recordType, _signature...>
37-
select(const std::string& pNamespace, const std::string& pRecord,
38-
enable_if_same<_recordType&, typename detail::TypeId<_signature...>::HEAD > *_= nullptr);
39-
40-
41-
template<class _recordType, class ..._signature>
42-
static constexpr const ConstructorBuilder<_recordType, _signature...>
43-
select(const std::string& pNamespace, const std::string& pRecord,
44-
enable_if_same<const _recordType&, typename detail::TypeId<_signature...>::HEAD > *_= nullptr);
45-
46-
47-
template<class _recordType, class ..._signature>
48-
static constexpr const ConstructorBuilder<_recordType, _signature...>
49-
select(const std::string& pNamespace, const std::string& pRecord,
50-
enable_if_not_same<_recordType&, typename detail::TypeId<_signature...>::HEAD > *_= nullptr,
51-
enable_if_not_same<const _recordType&, typename detail::TypeId<_signature...>::HEAD > *__= nullptr);
52-
};
53-
}
5426
}

ReflectionTemplateLib/builder/inc/ConstructorBuilder.hpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,4 @@ namespace rtl {
3939
}
4040
}
4141
}
42-
43-
44-
namespace builder
45-
{
46-
template<class _recordType, class ..._signature>
47-
inline constexpr const ConstructorBuilder<_recordType, _signature...>
48-
ConstructorBuilder<>::select(const std::string& pNamespace, const std::string& pRecord,
49-
enable_if_same<_recordType&, typename detail::TypeId<_signature...>::HEAD > *_)
50-
{
51-
return ConstructorBuilder<_recordType, _signature...>(pNamespace, pRecord, FunctorType::CopyCtor);
52-
}
53-
54-
55-
template<class _recordType, class ..._signature>
56-
inline constexpr const ConstructorBuilder<_recordType, _signature...>
57-
ConstructorBuilder<>::select(const std::string& pNamespace, const std::string& pRecord,
58-
enable_if_same<const _recordType&, typename detail::TypeId<_signature...>::HEAD > *_)
59-
{
60-
return ConstructorBuilder<_recordType, _signature...>(pNamespace, pRecord, FunctorType::CopyCtorConst);
61-
}
62-
63-
64-
template<class _recordType, class ..._signature>
65-
inline constexpr const ConstructorBuilder<_recordType, _signature...>
66-
ConstructorBuilder<>::select(const std::string& pNamespace, const std::string& pRecord,
67-
enable_if_not_same<_recordType&, typename detail::TypeId<_signature...>::HEAD > *_,
68-
enable_if_not_same<const _recordType&, typename detail::TypeId<_signature...>::HEAD > *__)
69-
{
70-
return ConstructorBuilder<_recordType, _signature...>(pNamespace, pRecord, FunctorType::Ctor);
71-
}
72-
}
7342
}

ReflectionTemplateLib/builder/inc/RecordBuilder.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ namespace rtl {
1818
template<class ..._signature>
1919
inline constexpr const ConstructorBuilder<_recordType, _signature...> RecordBuilder<_recordType>::constructor() const
2020
{
21-
return ConstructorBuilder<>::select<_recordType, _signature...>(m_namespace, m_record);
21+
if constexpr (std::is_same_v<_recordType&, typename detail::TypeId<_signature...>::HEAD>) {
22+
return ConstructorBuilder<_recordType, _signature...>(m_namespace, m_record, FunctorType::CopyCtor);
23+
}
24+
else if constexpr (std::is_same_v<const _recordType&, typename detail::TypeId<_signature...>::HEAD>) {
25+
return ConstructorBuilder<_recordType, _signature...>(m_namespace, m_record, FunctorType::CopyCtorConst);
26+
}
27+
else {
28+
return ConstructorBuilder<_recordType, _signature...>(m_namespace, m_record, FunctorType::Ctor);
29+
}
2230
}
2331

2432

0 commit comments

Comments
 (0)