Home | History | Annotate | Download | only in futures.promise
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // UNSUPPORTED: libcpp-has-no-threads
     11 
     12 // <future>
     13 
     14 // class promise<R>
     15 
     16 // void promise::set_value(const R& r);
     17 
     18 #include <future>
     19 #include <cassert>
     20 
     21 struct A
     22 {
     23     A() {}
     24     A(const A&) {throw 10;}
     25 };
     26 
     27 int main()
     28 {
     29     {
     30         typedef int T;
     31         T i = 3;
     32         std::promise<T> p;
     33         std::future<T> f = p.get_future();
     34         p.set_value(i);
     35         ++i;
     36         assert(f.get() == 3);
     37         --i;
     38         try
     39         {
     40             p.set_value(i);
     41             assert(false);
     42         }
     43         catch (const std::future_error& e)
     44         {
     45             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
     46         }
     47     }
     48     {
     49         typedef A T;
     50         T i;
     51         std::promise<T> p;
     52         std::future<T> f = p.get_future();
     53         try
     54         {
     55             p.set_value(i);
     56             assert(false);
     57         }
     58         catch (int j)
     59         {
     60             assert(j == 10);
     61         }
     62     }
     63 }
     64