[container] container_detail::pair piecewise constructor

Hi everyone, boost::container::container_detail::pair's piecewise constructor is missing, as acknowledged in a comment. This makes container::flat_map::emplace less useful (perhaps useless) as the following will not work: boost::container::flat_multimap<TestKey, TestValue> testMap; testMap.emplace(boost::container::container_detail::piecewise_construct, boost::make_tuple(30), boost::make_tuple(50)); where both TestKey and TestValue are non-copyable, moveable classes with a constructor taking an int. The compilation error message will correctly say that boost::container::container_detail::pair does not have a constructor with three arguments. I tried to implement the missing piecewise constructor based on std::pair's in the g++ standard libraries. I failed at it, so I would like to request some assistance and education. This is where I got: // from the standard lib template<std::size_t _Num> struct _Build_index_tuple { typedef typename _Build_index_tuple<_Num-1>::__type::__next __type; }; // from the standard lib template<> struct _Build_index_tuple<0> { typedef _Index_tuple<> __type; }; template <class... Args1, class... Args2> pair(piecewise_construct_t, ::boost::tuple<Args1...> first_args, ::boost::tuple<Args2...> second_args) : pair(::boost::move(first_args), ::boost::move(second_args), typename _Build_index_tuple<sizeof...(Args1)>::__type(), typename _Build_index_tuple<sizeof...(Args2)>::__type()) {} template<typename... Args1, std::size_t... Indices1, typename... Args2, std::size_t... Indices2> explicit pair(tuple<Args1...> tuple1, tuple<Args2...> tuple2, _Index_tuple<Indices1...>, _Index_tuple<Indices2...>) : first(::boost::forward<Args1>(std::get<Indices1>(tuple1))...), second(::boost::forward<Args2>(std::get<Indices2>(tuple2))...) { } This gets me a recursive error message far too long to quote, starting with: error C2664: 'boost::container::container_detail::pair<Key,T>::pair(std::pair<Key,T> &&)' : cannot convert parameter 3 from 'boost::tuples::tuple<int,boost::tuples::null_type // lot of null_types omitted to 'boost::tuples::tuple<boost::tuples::null_type, // lot of null_types omitted I used the VS2012 Nov CTP compiler. I understand that variadic templates have not been very portable and boost::unordered, which has a piecewise constructor implementation, does it completely differently and much more painfully. But is there a reason for the approach I tried not to work with boost at all? Could you please help me fix this code? Thank you very much, Laszlo Szecsi

On 14 November 2012 17:53, László Szécsi <szecsi@iit.bme.hu> wrote:
I understand that variadic templates have not been very portable and boost::unordered, which has a piecewise constructor implementation, does it completely differently and much more painfully.
Much of the complexity was from supporting the old variadic constructors for pairs, which were pretty problematic. Since that's been deprecated for some time (you need to define a macro to use it) I could probably remove it and that might lead to a simpler implementation. I suspect I'm the only person who ever used it anyway. Also, I didn't use the trick for constructing objects from tuples on compilers with variadic templates because I wasn't aware of it at the time. At some point I'll use it instead, but I'll still need the macros for compilers without full variadic support.

On Thu, Nov 15, 2012 at 12:45 PM, Daniel James <dnljms@gmail.com> wrote:
On 14 November 2012 17:53, László Szécsi <szecsi@iit.bme.hu> wrote:
boost::unordered, which has a piecewise constructor implementation,
Much of the complexity was from supporting the old variadic constructors for pairs, which were pretty problematic. ... but I'll still need the macros for compilers without full variadic support. Absolutely. Great work, well done! If only someone did the same for flat_map.

El 15/11/2012 14:12, László Szécsi escribió:
On Thu, Nov 15, 2012 at 12:45 PM, Daniel James <dnljms@gmail.com> wrote:
On 14 November 2012 17:53, László Szécsi <szecsi@iit.bme.hu> wrote:
boost::unordered, which has a piecewise constructor implementation,
Much of the complexity was from supporting the old variadic constructors for pairs, which were pretty problematic. ... but I'll still need the macros for compilers without full variadic support. Absolutely. Great work, well done! If only someone did the same for flat_map.
Can you please fill a ticket for this? The main problem is with compilers without variadic templates. Implementing piecewise construct for C++03 required a lot of job due to the internal C++11 pair emulation, so I decided to implement it later than some other neede features. I'll take a look to Unordered implementation to get some inspiration. However I'm afraid I won't have time to implement it shortly. We can maybe start with compilers supporting variadic templates and support other compilers in a future release. Best, Ion
participants (3)
-
Daniel James
-
Ion Gaztañaga
-
László Szécsi