brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5058a74 Raw
81 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// reference_wrapper12 13// reference_wrapper& operator=(const reference_wrapper<T>& x);14 15#include <functional>16#include <cassert>17 18#include "test_macros.h"19 20class functor121{22};23 24struct convertible_to_int_ref {25    int val = 0;26    operator int&() { return val; }27    operator int const&() const { return val; }28};29 30template <class T>31void32test(T& t)33{34    std::reference_wrapper<T> r(t);35    T t2 = t;36    std::reference_wrapper<T> r2(t2);37    r2 = r;38    assert(&r2.get() == &t);39}40 41void f() {}42void g() {}43 44void45test_function()46{47    std::reference_wrapper<void ()> r(f);48    std::reference_wrapper<void ()> r2(g);49    r2 = r;50    assert(&r2.get() == &f);51}52 53int main(int, char**)54{55    void (*fp)() = f;56    test(fp);57    test_function();58    functor1 f1;59    test(f1);60    int i = 0;61    test(i);62    const int j = 0;63    test(j);64 65#if TEST_STD_VER >= 1166    convertible_to_int_ref convi;67    test(convi);68    convertible_to_int_ref const convic;69    test(convic);70 71    {72    using Ref = std::reference_wrapper<int>;73    static_assert((std::is_assignable<Ref&, int&>::value), "");74    static_assert((!std::is_assignable<Ref&, int>::value), "");75    static_assert((!std::is_assignable<Ref&, int&&>::value), "");76    }77#endif78 79  return 0;80}81