1eb5cfb02SEric Fiselier //===----------------------------------------------------------------------===// 2eb5cfb02SEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6eb5cfb02SEric Fiselier // 7eb5cfb02SEric Fiselier //===----------------------------------------------------------------------===// 8eb5cfb02SEric Fiselier // 9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads 1031cbe0f2SLouis Dionne // UNSUPPORTED: c++03 11eb5cfb02SEric Fiselier 12eb5cfb02SEric Fiselier // <future> 13eb5cfb02SEric Fiselier 14eb5cfb02SEric Fiselier // class packaged_task<R(ArgTypes...)> 15eb5cfb02SEric Fiselier 16eb5cfb02SEric Fiselier // void reset(); 17eb5cfb02SEric Fiselier 18eb5cfb02SEric Fiselier #include <future> 19eb5cfb02SEric Fiselier #include <cassert> 20eb5cfb02SEric Fiselier 2108eb2148SAsiri Rathnayake #include "test_macros.h" 2208eb2148SAsiri Rathnayake 23eb5cfb02SEric Fiselier class A 24eb5cfb02SEric Fiselier { 25eb5cfb02SEric Fiselier long data_; 26eb5cfb02SEric Fiselier 27eb5cfb02SEric Fiselier public: A(long i)28eb5cfb02SEric Fiselier explicit A(long i) : data_(i) {} 29eb5cfb02SEric Fiselier operator ()(long i,long j) const30eb5cfb02SEric Fiselier long operator()(long i, long j) const 31eb5cfb02SEric Fiselier { 32eb5cfb02SEric Fiselier return data_ + i + j; 33eb5cfb02SEric Fiselier } 34eb5cfb02SEric Fiselier }; 35eb5cfb02SEric Fiselier main(int,char **)362df59c50SJF Bastienint main(int, char**) 37eb5cfb02SEric Fiselier { 38eb5cfb02SEric Fiselier { 39eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p(A(5)); 40eb5cfb02SEric Fiselier std::future<double> f = p.get_future(); 413f05377dSMuiez Ahmed p(3, 97); 42eb5cfb02SEric Fiselier assert(f.get() == 105.0); 43eb5cfb02SEric Fiselier p.reset(); 443f05377dSMuiez Ahmed p(4, 97); 45eb5cfb02SEric Fiselier f = p.get_future(); 46eb5cfb02SEric Fiselier assert(f.get() == 106.0); 47eb5cfb02SEric Fiselier } 4808eb2148SAsiri Rathnayake #ifndef TEST_HAS_NO_EXCEPTIONS 49eb5cfb02SEric Fiselier { 50eb5cfb02SEric Fiselier std::packaged_task<double(int, char)> p; 51eb5cfb02SEric Fiselier try 52eb5cfb02SEric Fiselier { 53eb5cfb02SEric Fiselier p.reset(); 54eb5cfb02SEric Fiselier assert(false); 55eb5cfb02SEric Fiselier } 56eb5cfb02SEric Fiselier catch (const std::future_error& e) 57eb5cfb02SEric Fiselier { 58eb5cfb02SEric Fiselier assert(e.code() == make_error_code(std::future_errc::no_state)); 59eb5cfb02SEric Fiselier } 60eb5cfb02SEric Fiselier } 6108eb2148SAsiri Rathnayake #endif 622df59c50SJF Bastien 632df59c50SJF Bastien return 0; 64eb5cfb02SEric Fiselier } 65