From 6b7dc4be36b8797d50698128344e62535fc61304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Wed, 21 May 2014 17:37:16 -0300 Subject: [PATCH] Greatly improved concepts/traits definition. The improvement was based on feedback[1] from "Felipe Magno de Almeida" . [1] http://pastie.org/9196937 --- include/boost/http/traits.hpp | 64 +++++++---------------------------- src/tests/socket_concept.cpp | 29 ++++++++++++---- 2 files changed, 35 insertions(+), 58 deletions(-) diff --git a/include/boost/http/traits.hpp b/include/boost/http/traits.hpp index ed481f8..231440f 100644 --- a/include/boost/http/traits.hpp +++ b/include/boost/http/traits.hpp @@ -13,69 +13,31 @@ struct is_message: public std::true_type {}; //< TODO: refine concept namespace detail { -template -struct has_outgoing_state_helper -{ - static constexpr bool value = false; -}; - -template -struct has_outgoing_state_helper -{ - static constexpr bool f(...) {return false;} - - static constexpr bool f(decltype((static_cast(0))->outgoing_state())*) - { - return std::is_same(0))->outgoing_state()), - boost::http::outgoing_state>::value; - } - - static constexpr bool value = f(0); -}; +template +struct has_outgoing_state : std::false_type +{}; -template::value /* TODO: make it work on is_final::value */> +template struct has_outgoing_state -{ - static bool constexpr value = false; -}; - -template -struct has_outgoing_state -{ - struct Fallback { - int outgoing_state; - }; - - struct Derived : T, Fallback { }; - - template - struct ChT; - - template - static std::false_type f(ChT*); - - template - static std::true_type f(...); - - static bool constexpr value2 = decltype(f(0))::value; - - static bool constexpr value = value2 && has_outgoing_state_helper::value; -}; +(nullptr) + ->outgoing_state()), + boost::http::outgoing_state>::type> + : std::true_type +{}; template -bool constexpr is_http_socket_helper() +constexpr bool is_http_socket_helper() { - return is_message::value - && has_outgoing_state::value; + return is_message::value && has_outgoing_state::value; } } // namespace detail template struct is_socket - : public std::conditional(), - std::true_type, std::false_type>::type + : std::integral_constant()> {}; } // namespace http } // namespace boost + diff --git a/src/tests/socket_concept.cpp b/src/tests/socket_concept.cpp index dd71e4d..d538ba9 100644 --- a/src/tests/socket_concept.cpp +++ b/src/tests/socket_concept.cpp @@ -5,31 +5,46 @@ #include class A -{ -}; +{}; -class B +struct B { -public: boost::http::outgoing_state outgoing_state() const; }; -class C: public B +struct C: B { }; -class D +struct D { -public: int outgoing_state() const; }; +struct E +{ + boost::http::outgoing_state outgoing_state(); +}; + +struct F +{ + struct X + { + operator boost::http::outgoing_state(); + }; + + X outgoing_state() const; +}; + BOOST_AUTO_TEST_CASE(Simple_attributes) { using namespace boost::http; BOOST_CHECK(!is_socket::value); BOOST_CHECK(!is_socket::value); + BOOST_CHECK(is_socket::value); BOOST_CHECK(is_socket::value); BOOST_CHECK(!is_socket::value); + BOOST_CHECK(!is_socket::value); + BOOST_CHECK(is_socket::value); BOOST_CHECK(is_socket>::value); }