Getting started on <future>
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@112061 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ef0036c5aa
commit
a652172d86
@ -463,6 +463,8 @@ enum _ {
|
||||
|
||||
};
|
||||
|
||||
template <> struct is_error_code_enum<future_errc> : public true_type {};
|
||||
|
||||
//enum class launch
|
||||
struct launch
|
||||
{
|
||||
@ -495,6 +497,32 @@ enum _ {
|
||||
|
||||
};
|
||||
|
||||
const error_category& future_category();
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
error_code
|
||||
make_error_code(future_errc __e)
|
||||
{
|
||||
return error_code(static_cast<int>(__e), future_category());
|
||||
}
|
||||
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
error_condition
|
||||
make_error_condition(future_errc __e)
|
||||
{
|
||||
return error_condition(static_cast<int>(__e), future_category());
|
||||
}
|
||||
|
||||
class future_error
|
||||
: public logic_error
|
||||
{
|
||||
error_code __ec_;
|
||||
public:
|
||||
future_error(error_code __ec);
|
||||
|
||||
const error_code& code() const throw() {return __ec_;}
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_FUTURE
|
||||
|
63
src/future.cpp
Normal file
63
src/future.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//===------------------------- future.cpp ---------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "future"
|
||||
#include "string"
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
class _LIBCPP_HIDDEN __future_error_category
|
||||
: public __do_message
|
||||
{
|
||||
public:
|
||||
virtual const char* name() const;
|
||||
virtual string message(int ev) const;
|
||||
};
|
||||
|
||||
const char*
|
||||
__future_error_category::name() const
|
||||
{
|
||||
return "future";
|
||||
}
|
||||
|
||||
string
|
||||
__future_error_category::message(int ev) const
|
||||
{
|
||||
switch (ev)
|
||||
{
|
||||
case future_errc::broken_promise:
|
||||
return string("The associated promise has been destructed prior "
|
||||
"to the associated state becoming ready.");
|
||||
case future_errc::future_already_retrieved:
|
||||
return string("The future has already been retrieved from "
|
||||
"the promise or packaged_task.");
|
||||
case future_errc::promise_already_satisfied:
|
||||
return string("The state of the promise has already been set.");
|
||||
case future_errc::no_state:
|
||||
return string("Operation not permitted on an object without "
|
||||
"an associated state.");
|
||||
}
|
||||
return string("unspecified future_errc value\n");
|
||||
}
|
||||
|
||||
|
||||
const error_category&
|
||||
future_category()
|
||||
{
|
||||
static __future_error_category __f;
|
||||
return __f;
|
||||
}
|
||||
|
||||
future_error::future_error(error_code __ec)
|
||||
: logic_error(__ec.message()),
|
||||
__ec_(__ec)
|
||||
{
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual error_condition default_error_condition(int ev) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
std::error_condition e_cond = e_cat.default_error_condition(std::errc::not_a_directory);
|
||||
assert(e_cond.category() == e_cat);
|
||||
assert(e_cond.value() == std::errc::not_a_directory);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual bool equivalent(const error_code& code, int condition) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
assert(e_cat.equivalent(std::error_code(5, e_cat), 5));
|
||||
assert(!e_cat.equivalent(std::error_code(5, e_cat), 6));
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
// virtual bool equivalent(int code, const error_condition& condition) const;
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& e_cat = std::future_category();
|
||||
std::error_condition e_cond = e_cat.default_error_condition(5);
|
||||
assert(e_cat.equivalent(5, e_cond));
|
||||
assert(!e_cat.equivalent(6, e_cond));
|
||||
}
|
22
test/thread/futures/futures.errors/future_category.pass.cpp
Normal file
22
test/thread/futures/futures.errors/future_category.pass.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// const error_category& future_category();
|
||||
|
||||
#include <future>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::error_category& ec = std::future_category();
|
||||
assert(std::strcmp(ec.name(), "future") == 0);
|
||||
}
|
26
test/thread/futures/futures.errors/make_error_code.pass.cpp
Normal file
26
test/thread/futures/futures.errors/make_error_code.pass.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// class error_code
|
||||
|
||||
// error_code make_error_code(future_errc e);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::error_code ec = make_error_code(std::future_errc::broken_promise);
|
||||
assert(ec.value() == static_cast<int>(std::future_errc::broken_promise));
|
||||
assert(ec.category() == std::future_category());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// class error_condition
|
||||
|
||||
// error_condition make_error_condition(future_errc e);
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::error_condition ec1 =
|
||||
std::make_error_condition(std::future_errc::future_already_retrieved);
|
||||
assert(ec1.value() ==
|
||||
static_cast<int>(std::future_errc::future_already_retrieved));
|
||||
assert(ec1.category() == std::future_category());
|
||||
}
|
||||
}
|
41
test/thread/futures/futures.future_error/code.pass.cpp
Normal file
41
test/thread/futures/futures.future_error/code.pass.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// class future_error
|
||||
|
||||
// const error_code& code() const throw();
|
||||
|
||||
#include <future>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::broken_promise);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::future_already_retrieved);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::promise_already_satisfied);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
{
|
||||
std::error_code ec = std::make_error_code(std::future_errc::no_state);
|
||||
std::future_error f(ec);
|
||||
assert(f.code() == ec);
|
||||
}
|
||||
}
|
21
test/thread/futures/futures.future_error/types.pass.cpp
Normal file
21
test/thread/futures/futures.future_error/types.pass.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// class future_error : public logic_error {...};
|
||||
|
||||
#include <future>
|
||||
#include <type_traits>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_convertible<std::future_error*,
|
||||
std::logic_error*>::value), "");
|
||||
}
|
41
test/thread/futures/futures.future_error/what.pass.cpp
Normal file
41
test/thread/futures/futures.future_error/what.pass.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// class future_error
|
||||
|
||||
// const char* what() const throw();
|
||||
|
||||
#include <future>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::broken_promise));
|
||||
assert(std::strcmp(f.what(), "The associated promise has been destructed prior "
|
||||
"to the associated state becoming ready.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::future_already_retrieved));
|
||||
assert(std::strcmp(f.what(), "The future has already been retrieved from "
|
||||
"the promise or packaged_task.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::promise_already_satisfied));
|
||||
assert(std::strcmp(f.what(), "The state of the promise has already been set.") == 0);
|
||||
}
|
||||
{
|
||||
std::future_error f(std::make_error_code(std::future_errc::no_state));
|
||||
assert(std::strcmp(f.what(), "Operation not permitted on an object without "
|
||||
"an associated state.") == 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <future>
|
||||
|
||||
// template <> struct is_error_code_enum<future_errc> : public true_type {};
|
||||
|
||||
#include <future>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::is_error_code_enum<std::future_errc>::value, "");
|
||||
}
|
13
test/thread/futures/futures.state/nothing_to_do.pass.cpp
Normal file
13
test/thread/futures/futures.state/nothing_to_do.pass.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// -*- C++ -*-
|
||||
//===-------------------------- algorithm ---------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user