brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · f61eee8 Raw
50 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// UNSUPPORTED: no-threads10// UNSUPPORTED: c++0311 12// <future>13 14// class promise<R>15 16// void promise<R&>::set_value(R& r);17 18#include <future>19#include <cassert>20 21#include "test_macros.h"22 23int main(int, char**)24{25    {26        typedef int& T;27        int i = 3;28        std::promise<T> p;29        std::future<T> f = p.get_future();30        p.set_value(i);31        int& j = f.get();32        assert(j == 3);33        ++i;34        assert(j == 4);35#ifndef TEST_HAS_NO_EXCEPTIONS36        try37        {38            p.set_value(i);39            assert(false);40        }41        catch (const std::future_error& e)42        {43            assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));44        }45#endif46    }47 48  return 0;49}50