From 31efdb54853176f74462dbcdfb55e3a77d27bc48 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 5 Sep 2001 03:22:31 +0000 Subject: [PATCH] Added support for assignment from std::pair. Test in tuple_test_bench.cpp enabled for MSVC version [SVN r11025] --- .../detail/tuple_basic_no_partial_spec.hpp | 52 ++++++++++++------- test/tuple_test_bench.cpp | 3 +- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp index 376c13a..8c08cda 100644 --- a/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp +++ b/include/boost/tuple/detail/tuple_basic_no_partial_spec.hpp @@ -32,6 +32,7 @@ #define BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP #include "boost/type_traits.hpp" +#include #if defined BOOST_MSVC #pragma warning(disable:4518) // storage-class or type specifier(s) unexpected here; ignored @@ -86,32 +87,33 @@ namespace boost { // cons builds a heterogenous list of types template - struct cons - { - typedef cons self_type; - typedef Head head_type; - typedef Tail tail_type; + struct cons + { + typedef cons self_type; + typedef Head head_type; + typedef Tail tail_type; - head_type head; - tail_type tail; + head_type head; + tail_type tail; - typename boost::add_reference::type get_head() { return head; } - typename boost::add_reference::type get_tail() { return tail; } + typename boost::add_reference::type get_head() { return head; } + typename boost::add_reference::type get_tail() { return tail; } - typename boost::add_reference::type get_head() const { return head; } - typename boost::add_reference::type get_tail() const { return tail; } + typename boost::add_reference::type get_head() const { return head; } + typename boost::add_reference::type get_tail() const { return tail; } - template - explicit cons(const Other& other) : head(other.head), tail(other.tail) +#if defined BOOST_MSVC + template + explicit cons(const head_type& h /* = head_type() */, // causes MSVC 6.5 to barf. + const Tail& t) : head(h), tail(t.head, t.tail) { } -#if defined BOOST_MSVC explicit cons(const head_type& h /* = head_type() */, // causes MSVC 6.5 to barf. - const tail_type& t = tail_type()) : - head(h), tail(t) + const null_type& t) : head(h), tail(t) { } + #else explicit cons(const head_type& h = head_type(), const tail_type& t = tail_type()) : @@ -347,16 +349,26 @@ namespace boost { { } - template - explicit tuple(const Other& other) : cons1(other) + template + explicit tuple(const cons& other) : + cons1(other.head, other.tail) { } - template - self_type& operator=(const Other& other) + template + self_type& operator=(const std::pair& other) + { + this->head = other.first; + this->tail.head = other.second; + return *this; + } + + template + self_type& operator=(const cons& other) { this->head = other.head; this->tail = other.tail; + return *this; } }; diff --git a/test/tuple_test_bench.cpp b/test/tuple_test_bench.cpp index af6d337..cc9f4a7 100644 --- a/test/tuple_test_bench.cpp +++ b/test/tuple_test_bench.cpp @@ -244,11 +244,10 @@ void foo4() // testing tie // testing assignment from std::pair void foo7() { -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) int i, j; tie (i, j) = std::make_pair(1, 2); BOOST_TEST(i == 1 && j == 2); -#endif + tuple a; #ifdef E11 a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2