set_lvalue.pass.cpp revision f39daa8e5a5f7d7eb19f391497a29b4fa0eec28d
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <future>
11
12// class promise<R>
13
14// void promise<R&>::set_value(R& r);
15
16#include <future>
17#include <cassert>
18
19int main()
20{
21    {
22        typedef int& T;
23        int i = 3;
24        std::promise<T> p;
25        std::future<T> f = p.get_future();
26        p.set_value(i);
27        assert(f.get() == 3);
28        ++i;
29        f = p.get_future();
30        assert(f.get() == 4);
31        try
32        {
33            p.set_value(i);
34            assert(false);
35        }
36        catch (const std::future_error& e)
37        {
38            assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
39        }
40    }
41}
42