From f859ae88d9a306a12d0fe552a9ac3b3f2d26e22f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Apr 2018 14:21:59 +0100 Subject: Simplify by replacing enable_if with if constexpr --- libdbpp/column.cpp | 19 ++++++++----------- libdbpp/selectcommandUtil.impl.h | 21 ++++++++++----------- libdbpp/testCore.cpp | 19 ++++++++----------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp index f8eae65..b660cd3 100644 --- a/libdbpp/column.cpp +++ b/libdbpp/column.cpp @@ -1,5 +1,4 @@ #include "column.h" -#include #include #include @@ -43,16 +42,14 @@ class Extract : public DB::HandleField { void blob(const Blob & v) override { (*this)(v); } void null() override { } - template - void operator()(const D &, - typename boost::disable_if, dummy>::type = 0) { - throw InvalidConversion(typeid(D).name(), typeid(T).name()); - } - - template - void operator()(const D & v, - typename boost::enable_if, dummy>::type = 0) { - target = (T)v; + template + void operator()(const D & v) { + if constexpr (std::is_convertible::value) { + target = (T)v; + } + else { + throw InvalidConversion(typeid(D).name(), typeid(T).name()); + } } T & target; diff --git a/libdbpp/selectcommandUtil.impl.h b/libdbpp/selectcommandUtil.impl.h index dfe6894..6446de0 100644 --- a/libdbpp/selectcommandUtil.impl.h +++ b/libdbpp/selectcommandUtil.impl.h @@ -6,20 +6,19 @@ /// @cond namespace DB { - template - inline typename std::enable_if= std::tuple_size::value>::type - forEachField(DB::SelectCommand *, const Func & func, const Fn & ... args) - { - func(args...); - } - template - inline typename std::enable_if::value>::type + inline void forEachField(DB::SelectCommand * sel, const Func & func, const Args & ... args) { - typename std::tuple_element::type a; - (*sel)[field] >> a; - forEachField(sel, func, args..., a); + if constexpr (field >= std::tuple_size::value) { + (void)sel; + func(args...); + } + else { + typename std::tuple_element::type a; + (*sel)[field] >> a; + forEachField(sel, func, args..., a); + } } template diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp index 890cb18..b55d16d 100644 --- a/libdbpp/testCore.cpp +++ b/libdbpp/testCore.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include namespace DB { @@ -31,16 +30,14 @@ class Assert : public DB::HandleField { void blob(const Blob & v) override { (*this)(v); } void null() override { } - template - void operator()(const D &, - typename boost::disable_if, dummy>::type = 0) { - BOOST_ERROR("Unexpected column type " << typeid(D).name()); - } - - template - void operator()(const D & v, - typename boost::enable_if, dummy>::type = 0) { - BOOST_REQUIRE_EQUAL(expected, v); + template + void operator()(const D & v) { + if constexpr (std::is_convertible::value) { + BOOST_REQUIRE_EQUAL(expected, v); + } + else { + BOOST_ERROR("Unexpected column type " << typeid(D).name()); + } } const T & expected; -- cgit v1.2.3