brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · ed4e0e9 Raw
112 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// <functional>10 11// template<class R, class ...Args>12// function(R(*)(Args...)) -> function<R(Args...)>;13 14// UNSUPPORTED: c++03, c++11, c++1415 16#include <functional>17#include <type_traits>18 19#include "test_macros.h"20 21struct R { };22struct A1 { };23struct A2 { };24struct A3 { };25 26R f0() { return {}; }27R f1(A1) { return {}; }28R f2(A1, A2) { return {}; }29R f3(A1, A2, A3) { return {}; }30R f4(A1 = {}) { return {}; }31 32int main(int, char**) {33  {34    // implicit35    std::function a = f0;36    ASSERT_SAME_TYPE(decltype(a), std::function<R()>);37 38    std::function b = &f0;39    ASSERT_SAME_TYPE(decltype(b), std::function<R()>);40 41    // explicit42    std::function c{f0};43    ASSERT_SAME_TYPE(decltype(c), std::function<R()>);44 45    std::function d{&f0};46    ASSERT_SAME_TYPE(decltype(d), std::function<R()>);47  }48  {49    // implicit50    std::function a = f1;51    ASSERT_SAME_TYPE(decltype(a), std::function<R(A1)>);52 53    std::function b = &f1;54    ASSERT_SAME_TYPE(decltype(b), std::function<R(A1)>);55 56    // explicit57    std::function c{f1};58    ASSERT_SAME_TYPE(decltype(c), std::function<R(A1)>);59 60    std::function d{&f1};61    ASSERT_SAME_TYPE(decltype(d), std::function<R(A1)>);62  }63  {64    // implicit65    std::function a = f2;66    ASSERT_SAME_TYPE(decltype(a), std::function<R(A1, A2)>);67 68    std::function b = &f2;69    ASSERT_SAME_TYPE(decltype(b), std::function<R(A1, A2)>);70 71    // explicit72    std::function c{f2};73    ASSERT_SAME_TYPE(decltype(c), std::function<R(A1, A2)>);74 75    std::function d{&f2};76    ASSERT_SAME_TYPE(decltype(d), std::function<R(A1, A2)>);77  }78  {79    // implicit80    std::function a = f3;81    ASSERT_SAME_TYPE(decltype(a), std::function<R(A1, A2, A3)>);82 83    std::function b = &f3;84    ASSERT_SAME_TYPE(decltype(b), std::function<R(A1, A2, A3)>);85 86    // explicit87    std::function c{f3};88    ASSERT_SAME_TYPE(decltype(c), std::function<R(A1, A2, A3)>);89 90    std::function d{&f3};91    ASSERT_SAME_TYPE(decltype(d), std::function<R(A1, A2, A3)>);92  }93  // Make sure defaulted arguments don't mess up the deduction94  {95    // implicit96    std::function a = f4;97    ASSERT_SAME_TYPE(decltype(a), std::function<R(A1)>);98 99    std::function b = &f4;100    ASSERT_SAME_TYPE(decltype(b), std::function<R(A1)>);101 102    // explicit103    std::function c{f4};104    ASSERT_SAME_TYPE(decltype(c), std::function<R(A1)>);105 106    std::function d{&f4};107    ASSERT_SAME_TYPE(decltype(d), std::function<R(A1)>);108  }109 110  return 0;111}112