88 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// REQUIRES: c++03 || c++11 || c++1410 11// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS12 13// <functional>14 15// reference_wrapper16 17// check for deriving from binary_function18 19#include <functional>20#include <type_traits>21 22#include "test_macros.h"23 24class functor125 : public std::unary_function<int, char>26{27};28 29class functor230 : public std::binary_function<char, int, double>31{32};33 34class functor335 : public std::unary_function<int, int>,36 public std::binary_function<char, int, double>37{38public:39 typedef float result_type;40};41 42class functor443 : public std::unary_function<int, int>,44 public std::binary_function<char, int, double>45{46public:47};48 49struct C50{51 typedef int argument_type;52 typedef int result_type;53};54 55int main(int, char**)56{57 static_assert((!std::is_base_of<std::binary_function<int, char, int>,58 std::reference_wrapper<functor1> >::value), "");59 static_assert((std::is_base_of<std::binary_function<char, int, double>,60 std::reference_wrapper<functor2> >::value), "");61 static_assert((std::is_base_of<std::binary_function<char, int, double>,62 std::reference_wrapper<functor3> >::value), "");63 static_assert((std::is_base_of<std::binary_function<char, int, double>,64 std::reference_wrapper<functor4> >::value), "");65 static_assert((!std::is_base_of<std::binary_function<int, int, int>,66 std::reference_wrapper<C> >::value), "");67 static_assert((!std::is_base_of<std::binary_function<int, int, float>,68 std::reference_wrapper<float ()> >::value), "");69 static_assert((!std::is_base_of<std::binary_function<int, int, float>,70 std::reference_wrapper<float (int)> >::value), "");71 static_assert((std::is_base_of<std::binary_function<int, int, float>,72 std::reference_wrapper<float (int, int)> >::value), "");73 static_assert((!std::is_base_of<std::binary_function<int, int, float>,74 std::reference_wrapper<float(*)()> >::value), "");75 static_assert((!std::is_base_of<std::binary_function<int, int, float>,76 std::reference_wrapper<float(*)(int)> >::value), "");77 static_assert((std::is_base_of<std::binary_function<int, int, float>,78 std::reference_wrapper<float(*)(int, int)> >::value), "");79 static_assert((!std::is_base_of<std::binary_function<C*, int, float>,80 std::reference_wrapper<float(C::*)()> >::value), "");81 static_assert((std::is_base_of<std::binary_function<C*, int, float>,82 std::reference_wrapper<float(C::*)(int)> >::value), "");83 static_assert((std::is_base_of<std::binary_function<const volatile C*, int, float>,84 std::reference_wrapper<float(C::*)(int) const volatile> >::value), "");85 86 return 0;87}88