Merge to upstream r226192.

Change-Id: Id459c8ce0d7dec371ff4d064ee2c71f6b7178e63
This commit is contained in:
Dan Albert
2015-01-15 14:32:55 -08:00
parent 2b3c63f704
commit 4dc5b2198d
144 changed files with 470 additions and 206 deletions

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::divides<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(36, 4) == 9);
#if _LIBCPP_STD_VER > 11
typedef std::divides<> F2;

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::minus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(3, 2) == 1);
#if _LIBCPP_STD_VER > 11
typedef std::minus<> F2;

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::modulus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(36, 8) == 4);
#if _LIBCPP_STD_VER > 11
typedef std::modulus<> F2;

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::multiplies<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(3, 2) == 6);
#if _LIBCPP_STD_VER > 11
typedef std::multiplies<> F2;

View File

@@ -19,7 +19,8 @@ int main()
{
typedef std::negate<int> F;
const F f = F();
static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), "");
static_assert((std::is_same<F::argument_type, int>::value), "" );
static_assert((std::is_same<F::result_type, int>::value), "" );
assert(f(36) == -36);
#if _LIBCPP_STD_VER > 11
typedef std::negate<> F2;

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::plus<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(3, 2) == 5);
#if _LIBCPP_STD_VER > 11
typedef std::plus<> F2;

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::bit_and<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(0xEA95, 0xEA95) == 0xEA95);
assert(f(0xEA95, 0x58D3) == 0x4891);
assert(f(0x58D3, 0xEA95) == 0x4891);

View File

@@ -20,7 +20,8 @@ int main()
#if _LIBCPP_STD_VER > 11
typedef std::bit_not<int> F;
const F f = F();
static_assert((std::is_base_of<std::unary_function<int, int>, F>::value), "");
static_assert((std::is_same<F::argument_type, int>::value), "" );
static_assert((std::is_same<F::result_type, int>::value), "" );
assert((f(0xEA95) & 0xFFFF ) == 0x156A);
assert((f(0x58D3) & 0xFFFF ) == 0xA72C);
assert((f(0) & 0xFFFF ) == 0xFFFF);

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::bit_or<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(0xEA95, 0xEA95) == 0xEA95);
assert(f(0xEA95, 0x58D3) == 0xFAD7);
assert(f(0x58D3, 0xEA95) == 0xFAD7);

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::bit_xor<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<int, F::result_type>::value), "" );
assert(f(0xEA95, 0xEA95) == 0);
assert(f(0xEA95, 0x58D3) == 0xB246);
assert(f(0x58D3, 0xEA95) == 0xB246);

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::equal_to<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(f(36, 36));
assert(!f(36, 6));
#if _LIBCPP_STD_VER > 11

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::greater<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(!f(36, 36));
assert(f(36, 6));
assert(!f(6, 36));

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::greater_equal<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(f(36, 36));
assert(f(36, 6));
assert(!f(6, 36));

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::less<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(!f(36, 36));
assert(!f(36, 6));
assert(f(6, 36));

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::less_equal<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(f(36, 36));
assert(!f(36, 6));
assert(f(6, 36));

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::not_equal_to<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(!f(36, 36));
assert(f(36, 6));
#if _LIBCPP_STD_VER > 11

View File

@@ -10,40 +10,99 @@
// <functional>
// template<Returnable R, CopyConstructible... ArgTypes>
// class function<R(ArgTypes...)>
// : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
// // ArgTypes contains T1
// : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
// // ArgTypes contains T1 and T2
// {
// class function<R(ArgTypes...)> {
// public:
// typedef R result_type;
// ...
// };
// typedef R result_type;
// typedef T1 argument_type; // iff sizeof...(ArgTypes) == 1 and
// // the type in ArgTypes is T1
// typedef T1 first_argument_type; // iff sizeof...(ArgTypes) == 2 and
// // ArgTypes contains T1 and T2
// typedef T2 second_argument_type; // iff sizeof...(ArgTypes) == 2 and
// // ArgTypes contains T1 and T2
// ...
// };
#include <functional>
#include <type_traits>
template <typename T>
class has_argument_type
{
typedef char yes;
typedef long no;
template <typename C> static yes check( typename C::argument_type * );
template <typename C> static no check(...);
public:
enum { value = sizeof(check<T>(0)) == sizeof(yes) };
};
template <typename T>
class has_first_argument_type
{
typedef char yes;
typedef long no;
template <typename C> static yes check( typename C::first_argument_type * );
template <typename C> static no check(...);
public:
enum { value = sizeof(check<T>(0)) == sizeof(yes) };
};
template <typename T>
class has_second_argument_type
{
typedef char yes;
typedef long no;
template <typename C> static yes check( typename C::second_argument_type *);
template <typename C> static no check(...);
public:
enum { value = sizeof(check<T>(0)) == sizeof(yes) };
};
template <class F, class return_type>
void test_nullary_function ()
{
static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
static_assert((!has_argument_type<F>::value), "" );
static_assert((!has_first_argument_type<F>::value), "" );
static_assert((!has_second_argument_type<F>::value), "" );
}
template <class F, class return_type, class arg_type>
void test_unary_function ()
{
static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
static_assert((std::is_same<typename F::argument_type, arg_type>::value), "" );
static_assert((!has_first_argument_type<F>::value), "" );
static_assert((!has_second_argument_type<F>::value), "" );
}
template <class F, class return_type, class arg_type1, class arg_type2>
void test_binary_function ()
{
static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
static_assert((std::is_same<typename F::first_argument_type, arg_type1>::value), "" );
static_assert((std::is_same<typename F::second_argument_type, arg_type2>::value), "" );
static_assert((!has_argument_type<F>::value), "" );
}
template <class F, class return_type>
void test_other_function ()
{
static_assert((std::is_same<typename F::result_type, return_type>::value), "" );
static_assert((!has_argument_type<F>::value), "" );
static_assert((!has_first_argument_type<F>::value), "" );
static_assert((!has_second_argument_type<F>::value), "" );
}
int main()
{
static_assert((!std::is_base_of<std::unary_function <int, int>,
std::function<int()> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, int>,
std::function<int()> >::value), "");
static_assert(( std::is_same< std::function<int()>::result_type,
int>::value), "");
static_assert(( std::is_base_of<std::unary_function <int, double>,
std::function<double(int)> >::value), "");
static_assert((!std::is_base_of<std::binary_function<int, int, double>,
std::function<double(int)> >::value), "");
static_assert(( std::is_same< std::function<double(int)>::result_type,
double>::value), "");
static_assert((!std::is_base_of<std::unary_function <int, double>,
std::function<double(int, char)> >::value), "");
static_assert(( std::is_base_of<std::binary_function<int, char, double>,
std::function<double(int, char)> >::value), "");
static_assert(( std::is_same< std::function<double(int, char)>::result_type,
double>::value), "");
test_nullary_function<std::function<int()>, int>();
test_unary_function <std::function<double(int)>, double, int>();
test_binary_function <std::function<double(int, char)>, double, int, char>();
test_other_function <std::function<double(int, char, double)>, double>();
}

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::logical_and<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(f(36, 36));
assert(!f(36, 0));
assert(!f(0, 36));

View File

@@ -19,7 +19,8 @@ int main()
{
typedef std::logical_not<int> F;
const F f = F();
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
static_assert((std::is_same<F::argument_type, int>::value), "" );
static_assert((std::is_same<F::result_type, bool>::value), "" );
assert(!f(36));
assert(f(0));
#if _LIBCPP_STD_VER > 11

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::logical_or<int> F;
const F f = F();
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(f(36, 36));
assert(f(36, 0));
assert(f(0, 36));

View File

@@ -19,7 +19,9 @@ int main()
{
typedef std::binary_negate<std::logical_and<int> > F;
const F f = F(std::logical_and<int>());
static_assert((std::is_base_of<std::binary_function<int, int, bool>, F>::value), "");
static_assert((std::is_same<int, F::first_argument_type>::value), "" );
static_assert((std::is_same<int, F::second_argument_type>::value), "" );
static_assert((std::is_same<bool, F::result_type>::value), "" );
assert(!f(36, 36));
assert( f(36, 0));
assert( f(0, 36));

View File

@@ -19,7 +19,8 @@ int main()
{
typedef std::unary_negate<std::logical_not<int> > F;
const F f = F(std::logical_not<int>());
static_assert((std::is_base_of<std::unary_function<int, bool>, F>::value), "");
static_assert((std::is_same<F::argument_type, int>::value), "" );
static_assert((std::is_same<F::result_type, bool>::value), "" );
assert(f(36));
assert(!f(0));
}

View File

@@ -33,11 +33,12 @@ template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
typedef typename std::underlying_type<T>::type under_type;
std::hash<T> h1;
H h1;
std::hash<under_type> h2;
for (int i = 0; i <= 5; ++i)
{

View File

@@ -28,9 +28,11 @@ template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
std::size_t t0 = h(0.);
std::size_t tn0 = h(-0.);
std::size_t tp1 = h(0.1);

View File

@@ -27,9 +27,11 @@ template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
for (int i = 0; i <= 5; ++i)
{
T t(i);

View File

@@ -27,9 +27,11 @@ template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
H h;
typedef typename std::remove_pointer<T>::type type;
type i;
type j;