From dae3481b28ad0bedd4c5b98385af499cbbe2a10b Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 25 Aug 2010 17:32:05 +0000 Subject: [PATCH] Getting started on llvm-svn: 112061 --- libcxx/include/future | 28 +++++++++ libcxx/src/future.cpp | 63 +++++++++++++++++++ .../default_error_condition.pass.cpp | 25 ++++++++ .../equivalent_error_code_int.pass.cpp | 24 +++++++ .../equivalent_int_error_condition.pass.cpp | 25 ++++++++ .../futures.errors/future_category.pass.cpp | 22 +++++++ .../futures.errors/make_error_code.pass.cpp | 26 ++++++++ .../make_error_condition.pass.cpp | 28 +++++++++ .../futures.future_error/code.pass.cpp | 41 ++++++++++++ .../futures.future_error/types.pass.cpp | 21 +++++++ .../futures.future_error/what.pass.cpp | 41 ++++++++++++ .../is_error_code_enum_future_errc.pass.cpp | 19 ++++++ .../futures.state/nothing_to_do.pass.cpp | 13 ++++ 13 files changed, 376 insertions(+) create mode 100644 libcxx/src/future.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/default_error_condition.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/equivalent_error_code_int.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/equivalent_int_error_condition.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/future_category.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/make_error_code.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.errors/make_error_condition.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.future_error/code.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.future_error/types.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.future_error/what.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.overview/is_error_code_enum_future_errc.pass.cpp create mode 100644 libcxx/test/thread/futures/futures.state/nothing_to_do.pass.cpp diff --git a/libcxx/include/future b/libcxx/include/future index 54b751f1a1ed..c8986489d6ee 100644 --- a/libcxx/include/future +++ b/libcxx/include/future @@ -463,6 +463,8 @@ enum _ { }; +template <> struct is_error_code_enum : 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(__e), future_category()); +} + +inline _LIBCPP_INLINE_VISIBILITY +error_condition +make_error_condition(future_errc __e) +{ + return error_condition(static_cast(__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 diff --git a/libcxx/src/future.cpp b/libcxx/src/future.cpp new file mode 100644 index 000000000000..f9547c6609e5 --- /dev/null +++ b/libcxx/src/future.cpp @@ -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 diff --git a/libcxx/test/thread/futures/futures.errors/default_error_condition.pass.cpp b/libcxx/test/thread/futures/futures.errors/default_error_condition.pass.cpp new file mode 100644 index 000000000000..b792a6601bd5 --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/default_error_condition.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// const error_category& future_category(); + +// virtual error_condition default_error_condition(int ev) const; + +#include +#include + +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); +} diff --git a/libcxx/test/thread/futures/futures.errors/equivalent_error_code_int.pass.cpp b/libcxx/test/thread/futures/futures.errors/equivalent_error_code_int.pass.cpp new file mode 100644 index 000000000000..2c7aa89e35a9 --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/equivalent_error_code_int.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// const error_category& future_category(); + +// virtual bool equivalent(const error_code& code, int condition) const; + +#include +#include + +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)); +} diff --git a/libcxx/test/thread/futures/futures.errors/equivalent_int_error_condition.pass.cpp b/libcxx/test/thread/futures/futures.errors/equivalent_int_error_condition.pass.cpp new file mode 100644 index 000000000000..b24a53c18e2b --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/equivalent_int_error_condition.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// const error_category& future_category(); + +// virtual bool equivalent(int code, const error_condition& condition) const; + +#include +#include + +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)); +} diff --git a/libcxx/test/thread/futures/futures.errors/future_category.pass.cpp b/libcxx/test/thread/futures/futures.errors/future_category.pass.cpp new file mode 100644 index 000000000000..56a29d62c511 --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/future_category.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// const error_category& future_category(); + +#include +#include +#include + +int main() +{ + const std::error_category& ec = std::future_category(); + assert(std::strcmp(ec.name(), "future") == 0); +} diff --git a/libcxx/test/thread/futures/futures.errors/make_error_code.pass.cpp b/libcxx/test/thread/futures/futures.errors/make_error_code.pass.cpp new file mode 100644 index 000000000000..400905647be3 --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/make_error_code.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class error_code + +// error_code make_error_code(future_errc e); + +#include +#include + +int main() +{ + { + std::error_code ec = make_error_code(std::future_errc::broken_promise); + assert(ec.value() == static_cast(std::future_errc::broken_promise)); + assert(ec.category() == std::future_category()); + } +} diff --git a/libcxx/test/thread/futures/futures.errors/make_error_condition.pass.cpp b/libcxx/test/thread/futures/futures.errors/make_error_condition.pass.cpp new file mode 100644 index 000000000000..6a9b554235b7 --- /dev/null +++ b/libcxx/test/thread/futures/futures.errors/make_error_condition.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class error_condition + +// error_condition make_error_condition(future_errc e); + +#include +#include + +int main() +{ + { + const std::error_condition ec1 = + std::make_error_condition(std::future_errc::future_already_retrieved); + assert(ec1.value() == + static_cast(std::future_errc::future_already_retrieved)); + assert(ec1.category() == std::future_category()); + } +} diff --git a/libcxx/test/thread/futures/futures.future_error/code.pass.cpp b/libcxx/test/thread/futures/futures.future_error/code.pass.cpp new file mode 100644 index 000000000000..9b7407ae95b1 --- /dev/null +++ b/libcxx/test/thread/futures/futures.future_error/code.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class future_error + +// const error_code& code() const throw(); + +#include +#include + +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); + } +} diff --git a/libcxx/test/thread/futures/futures.future_error/types.pass.cpp b/libcxx/test/thread/futures/futures.future_error/types.pass.cpp new file mode 100644 index 000000000000..9802051f3668 --- /dev/null +++ b/libcxx/test/thread/futures/futures.future_error/types.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class future_error : public logic_error {...}; + +#include +#include + +int main() +{ + static_assert((std::is_convertible::value), ""); +} diff --git a/libcxx/test/thread/futures/futures.future_error/what.pass.cpp b/libcxx/test/thread/futures/futures.future_error/what.pass.cpp new file mode 100644 index 000000000000..082308da8205 --- /dev/null +++ b/libcxx/test/thread/futures/futures.future_error/what.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// class future_error + +// const char* what() const throw(); + +#include +#include +#include + +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); + } +} diff --git a/libcxx/test/thread/futures/futures.overview/is_error_code_enum_future_errc.pass.cpp b/libcxx/test/thread/futures/futures.overview/is_error_code_enum_future_errc.pass.cpp new file mode 100644 index 000000000000..ba5f6e7c9c51 --- /dev/null +++ b/libcxx/test/thread/futures/futures.overview/is_error_code_enum_future_errc.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template <> struct is_error_code_enum : public true_type {}; + +#include + +int main() +{ + static_assert(std::is_error_code_enum::value, ""); +} diff --git a/libcxx/test/thread/futures/futures.state/nothing_to_do.pass.cpp b/libcxx/test/thread/futures/futures.state/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b85601fc46fd --- /dev/null +++ b/libcxx/test/thread/futures/futures.state/nothing_to_do.pass.cpp @@ -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() +{ +}