brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · e90e395 Raw
62 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// future<R> get_future();17 18#include <future>19#include <cassert>20 21#include "test_macros.h"22 23int main(int, char**)24{25    {26        std::promise<double> p;27        std::future<double> f = p.get_future();28        p.set_value(105.5);29        assert(f.get() == 105.5);30    }31#ifndef TEST_HAS_NO_EXCEPTIONS32    {33        std::promise<double> p;34        std::future<double> f = p.get_future();35        try36        {37            f = p.get_future();38            assert(false);39        }40        catch (const std::future_error& e)41        {42            assert(e.code() ==  make_error_code(std::future_errc::future_already_retrieved));43        }44    }45    {46        std::promise<double> p;47        std::promise<double> p0 = std::move(p);48        try49        {50            std::future<double> f = p.get_future();51            assert(false);52        }53        catch (const std::future_error& e)54        {55            assert(e.code() ==  make_error_code(std::future_errc::no_state));56        }57    }58#endif59 60  return 0;61}62