From 3b116fe6ef5fdfe6f32a81364013ffef04c4d5c5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 24 Mar 2016 17:32:19 +0100 Subject: [PATCH] find a way to pick a default implementation for collection binding ...through the use of partial specialisation and SFINAE. There are some rather specific (yet expectedly not uncommon) cases, where we'd be able to provide a sensible default for the - match predicate - new element constructor of the binding. While in all other cases, the user has to provide an explicit implementation for these crucial building blocks anyway. --- .../diff/tree-mutator-collection-binding.hpp | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/src/lib/diff/tree-mutator-collection-binding.hpp b/src/lib/diff/tree-mutator-collection-binding.hpp index 03f7c5c79..741f8f3e5 100644 --- a/src/lib/diff/tree-mutator-collection-binding.hpp +++ b/src/lib/diff/tree-mutator-collection-binding.hpp @@ -383,6 +383,55 @@ }; + using lib::meta::Yes_t; + using lib::meta::No_t; + using lib::meta::enable_if; + + template + struct can_wrap_in_GenNode + { + template + static Yes_t check(typename lib::variant::CanBuildFrom::Type*); + template + static No_t check(...); + + public: + static const bool value = (sizeof(Yes_t)==sizeof(check(0))); + }; + + + template + struct _DefaultPayload + { + static bool + match (GenNode const& spec, ELM const& elm) + { + UNIMPLEMENTED("lalü"); + } + + static ELM + construct (GenNode const& spec) + { + UNIMPLEMENTED("lalü"); + } + }; + + template + struct _DefaultPayload>> + { + static bool + match (GenNode const& spec, ELM const& elm) + { + return spec.matches(elm); + } + + static ELM + construct (GenNode const& spec) + { + return spec.data.get(); + } + }; + /** * starting point for configuration of a binding to STL container. * When using the "nested DSL" to setup a binding to child elements @@ -400,17 +449,7 @@ using Coll = typename Strip::TypeReferred; using Elm = typename Coll::value_type; - static bool - default_contentMatch (GenNode const& spec, Elm const& elm) - { - return spec.matches(elm); - } - - static Elm - default_construct_from_payload (GenNode const& spec) - { - return spec.data.get(); - } + using Payload = _DefaultPayload; static bool disable_selector (GenNode const&) @@ -433,8 +472,8 @@ using FallbackBindingConfiguration = CollectionBindingBuilder