Add declval and common type from Vicente J. Botet Escriba.

Regenerate docs.

[SVN r65443]
This commit is contained in:
John Maddock
2010-09-17 12:12:03 +00:00
parent e66ffd9a99
commit afd6785017
43 changed files with 1779 additions and 50 deletions
+2
View File
@@ -32,5 +32,7 @@ rule all-tests {
test-suite type_traits : [ all-tests ] ;
compile-fail common_type_fail.cpp ;
@@ -16,10 +16,23 @@
# include <boost/type_traits/alignment_of.hpp>
#endif
//
// Need to defined some member functions for empty_UDT,
// we don't want to put these in the test.hpp as that
// causes overly-clever compilers to figure out that they can't throw
// which in turn breaks other tests.
//
empty_UDT::empty_UDT(){}
empty_UDT::~empty_UDT(){}
empty_UDT::empty_UDT(const empty_UDT&){}
empty_UDT& empty_UDT::operator=(const empty_UDT&){ return *this; }
bool empty_UDT::operator==(const empty_UDT&)const{ return true; }
//
// VC++ emits an awful lot of warnings unless we define these:
#ifdef BOOST_MSVC
# pragma warning(disable:4244)
# pragma warning(disable:4244 4121)
//
// What follows here is the test case for issue 1946.
//
+28
View File
@@ -0,0 +1,28 @@
// common_type_test.cpp ----------------------------------------------------//
// Copyright 2010 Beman Dawes
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness
#include "test.hpp"
#ifndef TEST_STD
#include <boost/type_traits/common_type.hpp>
#else
#include <type_traits>
#endif
struct C1 {
//~ private:
//~ C1();
};
struct C2 {};
typedef tt::common_type<C1, C2>::type AC;
+103
View File
@@ -0,0 +1,103 @@
// common_type_test.cpp ----------------------------------------------------//
// Copyright 2010 Beman Dawes
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include "test.hpp"
#include "check_type.hpp"
#ifdef TEST_STD
# include <type_traits>
#else
# include <boost/type_traits/common_type.hpp>
#endif
#include <iostream>
struct C1 {};
struct C2 {};
struct C3 : C2 {};
struct C1C2 {
C1C2() {}
C1C2(C1 const&) {}
C1C2(C2 const&) {}
C1C2& operator=(C1C2 const&) {
return *this;
}
};
template <typename C, typename A>
void proc2(typename boost::common_type<A, C>::type const& ) {}
template <typename C, typename A, typename B>
void proc3(typename boost::common_type<C, A, B>::type const& ) {}
template <typename C, typename A>
void assignation_2() {
typedef typename boost::common_type<A, C>::type AC;
A a;
C c;
AC ac;
ac=a;
ac=c;
proc2<C, A>(a);
proc2<C, A>(c);
}
template <typename C, typename A, typename B>
void assignation_3() {
typedef typename boost::common_type<C, A, B>::type ABC;
A a;
B b;
C c;
ABC abc;
abc=a;
abc=b;
abc=c;
proc3<C, A, B>(a);
proc3<C, A, B>(b);
proc3<C, A, B>(c);
}
C1C2 c1c2;
C1 c1;
int f(C1C2 ) { return 1;}
int f(C1 ) { return 2;}
template <typename OSTREAM>
OSTREAM& operator<<(OSTREAM& os, C1 const&) {return os;}
C1C2& declval_C1C2() {return c1c2;}
C1& declval_C1(){return c1;}
bool declval_bool(){return true;}
TT_TEST_BEGIN(common_type)
{
assignation_2<C1C2, C1>();
typedef tt::common_type<C1C2&, C1&>::type T1;
typedef tt::common_type<C3*, C2*>::type T2;
typedef tt::common_type<int*, int const*>::type T3;
#if defined(BOOST_NO_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
// fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF:
typedef tt::common_type<int volatile*, int const*>::type T4;
#endif
typedef tt::common_type<int*, int volatile*>::type T5;
assignation_2<C1, C1C2>();
assignation_2<C1C2, C2>();
assignation_2<C2, C1C2>();
assignation_3<C1, C1C2, C2>();
assignation_3<C1C2, C1, C2>();
assignation_3<C2, C1C2, C1>();
assignation_3<C1C2, C2, C1>();
//assignation_3<C1, C2, C1C2>(); // fails because the common type is the third
}
TT_TEST_END