From 95a003f7bdec4ad26e2e0e27996211428b1df19a Mon Sep 17 00:00:00 2001 From: Robin Eckert Date: Fri, 22 May 2015 14:28:08 +0200 Subject: [PATCH] Add an "inplace_assign" functor to boost::icl::interval_map The functor always overwrites values already in the container. --- doc/concepts.qbk | 3 ++- doc/icl.qbk | 1 + include/boost/icl/functors.hpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/concepts.qbk b/doc/concepts.qbk index bb1ec18..1b6bd40 100644 --- a/doc/concepts.qbk +++ b/doc/concepts.qbk @@ -208,11 +208,12 @@ For `Combine` functors, the Icl provides an __inverse__ functor. [[__ip_star__``] [__ip_slash__``] ] [[__ip_max__``] [__ip_min__``] ] [[__ip_identity__``][__ip_erasure__``]] +[[__ip_assign__``] [`no inverse`]] [[`Functor`] [__ip_erasure__``]] ] The meta function __inverse__ is mutually implemented for -all but the default functor `Functor` +all but the default functor `Functor` and the assign functor such that e.g. `inverse >::type` yields `inplace_plus`. Not in every case, e.g. `max/min`, does the __inverse__ functor diff --git a/doc/icl.qbk b/doc/icl.qbk index 3823f29..6040e11 100644 --- a/doc/icl.qbk +++ b/doc/icl.qbk @@ -92,6 +92,7 @@ Distributed under the Boost Software License, Version 1.0. [def __ip_caret__ [classref boost::icl::inplace_caret inplace_caret]] [def __ip_min__ [classref boost::icl::inplace_min inplace_min]] [def __ip_max__ [classref boost::icl::inplace_max inplace_max]] +[def __ip_assign__ [classref boost::icl::inplace_assign inplace_assign]] [def __ip_identity__ [classref boost::icl::inplace_identity inplace_identity]] [def __ip_erasure__ [classref boost::icl::inplace_erasure inplace_erasure]] [def __ip_bitset_union__ [classref boost::icl::inplace_bitset_union inplace_bitset_union]] diff --git a/include/boost/icl/functors.hpp b/include/boost/icl/functors.hpp index 2401b2b..ffaf722 100644 --- a/include/boost/icl/functors.hpp +++ b/include/boost/icl/functors.hpp @@ -252,6 +252,22 @@ namespace boost{namespace icl template<> inline std::string unary_template_to_string::apply() { return "min="; } + + // ------------------------------------------------------------------------ + template struct inplace_assign + : public identity_based_inplace_combine + { + typedef inplace_assign type; + + void operator()(Type& object, const Type& operand)const + { + object = operand; + } + }; + + template<> + inline std::string unary_template_to_string::apply() { return "="; } + //-------------------------------------------------------------------------- // Inter_section functor //--------------------------------------------------------------------------