forked from boostorg/tuple
Added support for assignment from std::pair. Test in tuple_test_bench.cpp enabled for MSVC version
[SVN r11025]
This commit is contained in:
@ -32,6 +32,7 @@
|
|||||||
#define BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP
|
#define BOOST_TUPLE_BASIC_NO_PARTIAL_SPEC_HPP
|
||||||
|
|
||||||
#include "boost/type_traits.hpp"
|
#include "boost/type_traits.hpp"
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#if defined BOOST_MSVC
|
#if defined BOOST_MSVC
|
||||||
#pragma warning(disable:4518) // storage-class or type specifier(s) unexpected here; ignored
|
#pragma warning(disable:4518) // storage-class or type specifier(s) unexpected here; ignored
|
||||||
@ -101,17 +102,18 @@ namespace boost {
|
|||||||
typename boost::add_reference<const head_type>::type get_head() const { return head; }
|
typename boost::add_reference<const head_type>::type get_head() const { return head; }
|
||||||
typename boost::add_reference<const tail_type>::type get_tail() const { return tail; }
|
typename boost::add_reference<const tail_type>::type get_tail() const { return tail; }
|
||||||
|
|
||||||
template<typename Other>
|
#if defined BOOST_MSVC
|
||||||
explicit cons(const Other& other) : head(other.head), tail(other.tail)
|
template<typename Tail>
|
||||||
|
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.
|
explicit cons(const head_type& h /* = head_type() */, // causes MSVC 6.5 to barf.
|
||||||
const tail_type& t = tail_type()) :
|
const null_type& t) : head(h), tail(t)
|
||||||
head(h), tail(t)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
explicit cons(const head_type& h = head_type(),
|
explicit cons(const head_type& h = head_type(),
|
||||||
const tail_type& t = tail_type()) :
|
const tail_type& t = tail_type()) :
|
||||||
@ -347,16 +349,26 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Other>
|
template<typename Head, typename Tail>
|
||||||
explicit tuple(const Other& other) : cons1(other)
|
explicit tuple(const cons<Head, Tail>& other) :
|
||||||
|
cons1(other.head, other.tail)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Other>
|
template<typename First, typename Second>
|
||||||
self_type& operator=(const Other& other)
|
self_type& operator=(const std::pair<First, Second>& other)
|
||||||
|
{
|
||||||
|
this->head = other.first;
|
||||||
|
this->tail.head = other.second;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Head, typename Tail>
|
||||||
|
self_type& operator=(const cons<Head, Tail>& other)
|
||||||
{
|
{
|
||||||
this->head = other.head;
|
this->head = other.head;
|
||||||
this->tail = other.tail;
|
this->tail = other.tail;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -244,11 +244,10 @@ void foo4()
|
|||||||
// testing tie
|
// testing tie
|
||||||
// testing assignment from std::pair
|
// testing assignment from std::pair
|
||||||
void foo7() {
|
void foo7() {
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
||||||
int i, j;
|
int i, j;
|
||||||
tie (i, j) = std::make_pair(1, 2);
|
tie (i, j) = std::make_pair(1, 2);
|
||||||
BOOST_TEST(i == 1 && j == 2);
|
BOOST_TEST(i == 1 && j == 2);
|
||||||
#endif
|
|
||||||
tuple<int, int, float> a;
|
tuple<int, int, float> a;
|
||||||
#ifdef E11
|
#ifdef E11
|
||||||
a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
|
a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
|
||||||
|
Reference in New Issue
Block a user