2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-21 17:32:18 +00:00
Files
thread/test/sync/futures/promise/set_value_const_pass.cpp
Andrey Semashev 8ebd61c280 Avoid relying on implicit copy constructor/operator deprecated in C++11.
C++11 deprecates implicit default copy constructors and operators if the class
has user-defined destructor or copy constructor/operator. gcc 9 generates
warnings when this deprecated language feature is used. This commit fixes that
by providing user-defained copy constructors/operators where needed. The
added definitions are equivalent to the implicitly generated by the compiler.

For thread::id, removed copy constructor to allow the compiler generate all
set of constructors and assignment operators, including move.
2020-04-05 02:17:14 +03:00

119 lines
2.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2011 Vicente J. Botet Escriba
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// <boost/thread/future.hpp>
// class promise<R>
// void promise::set_value(const R& r);
#define BOOST_THREAD_VERSION 3
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/static_assert.hpp>
#include <boost/config.hpp>
#ifdef BOOST_MSVC
# pragma warning(disable: 4702) // unreachable code
#endif
struct A
{
A()
{
}
A(const A&)
{
throw 10;
}
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
A& operator= (const A&) = default;
#endif
};
int main()
{
{
typedef int T;
T i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value(i);
++i;
BOOST_TEST(f.get() == 3);
--i;
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef int T;
T i = 3;
boost::promise<T> p;
boost::future<T> f = p.get_future();
p.set_value_deferred(i);
p.notify_deferred();
++i;
BOOST_TEST(f.get() == 3);
--i;
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (const boost::future_error& e)
{
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::promise_already_satisfied));
}
catch (...)
{
BOOST_TEST(false);
}
}
{
typedef A T;
T i;
boost::promise<T> p;
boost::future<T> f = p.get_future();
try
{
p.set_value(i);
BOOST_TEST(false);
}
catch (int j)
{
BOOST_TEST(j == 10);
}
catch (...)
{
BOOST_TEST(false);
}
}
return boost::report_errors();
}