diff --git a/include/continuable/continuable-types.hpp b/include/continuable/continuable-types.hpp new file mode 100644 index 0000000..b51e2e5 --- /dev/null +++ b/include/continuable/continuable-types.hpp @@ -0,0 +1,109 @@ + +/* + + /~` _ _ _|_. _ _ |_ | _ + \_,(_)| | | || ||_|(_||_)|(/_ + + https://github.com/Naios/continuable + v2.0.0 + + Copyright(c) 2015 - 2018 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +**/ + +#ifndef CONTINUABLE_TYPES_HPP_INCLUDED__ +#define CONTINUABLE_TYPES_HPP_INCLUDED__ + +#include + +#include + +#include +#include + +namespace cti { +// clang-format off +namespace detail { +/// A function which isn't size adjusted and copyable +template +using function_adapter = fu2::function; +/// A function which isn't size adjusted and move only +template +using unique_function_adapter = fu2::unique_function; +/// A function which is size adjusted and copyable +template +using function_adjustable = fu2::function_base; +/// A function which is size adjusted and move only +template +using unique_function_adjustable = fu2::function_base; + +/// We adjust the internal capacity of the outer function wrapper so +/// we don't have to allocate twice when using `continuable<...>`. +template +using trait_of = continuable_trait< + unique_function_adapter, + function_adjustable, + Args... +>; + +template +using unique_trait_of = continuable_trait< + unique_function_adapter, + unique_function_adjustable, + Args... +>; +} // namespace detail + +/// Defines a copyable continuation type which uses the +/// function2 backend for type erasure. +/// +/// Usable like: `cti::continuable` +template +using continuable = typename detail::trait_of< + Args... +>::continuable; + +/// Defines a non-copyable continuation type which uses the +/// function2 backend for type erasure. +/// +/// Usable like: `unique_continuable` +template +using unique_continuable = typename detail::unique_trait_of< + Args... +>::continuable; + +/// Defines a non-copyable promise type which is using the +/// function2 backend for type erasure. +/// +/// Usable like: `promise` +template +using promise = typename detail::unique_trait_of< + Args... +>::promise; + +// TODO channel +// TODO sink + +// clang-format on +} // namespace cti + +#endif // CONTINUABLE_TYPES_HPP_INCLUDED__ diff --git a/include/continuable/continuable.hpp b/include/continuable/continuable.hpp index 7d2a2b0..2ec38ef 100644 --- a/include/continuable/continuable.hpp +++ b/include/continuable/continuable.hpp @@ -31,79 +31,12 @@ #ifndef CONTINUABLE_HPP_INCLUDED__ #define CONTINUABLE_HPP_INCLUDED__ -#include - -#include - #include +#include +#include +#include #include - -namespace cti { -// clang-format off -namespace detail { -/// A function which isn't size adjusted and copyable -template -using function_adapter = fu2::function; -/// A function which isn't size adjusted and move only -template -using unique_function_adapter = fu2::unique_function; -/// A function which is size adjusted and copyable -template -using function_adjustable = fu2::function_base; -/// A function which is size adjusted and move only -template -using unique_function_adjustable = fu2::function_base; - -/// We adjust the internal capacity of the outer function wrapper so -/// we don't have to allocate twice when using `continuable<...>`. -template -using trait_of = continuable_trait< - unique_function_adapter, - function_adjustable, - Args... ->; - -template -using unique_trait_of = continuable_trait< - unique_function_adapter, - unique_function_adjustable, - Args... ->; -} // namespace detail - -/// Defines a copyable continuation type which uses the -/// function2 backend for type erasure. -/// -/// Usable like: `cti::continuable` -template -using continuable = typename detail::trait_of< - Args... ->::continuable; - -/// Defines a non-copyable continuation type which uses the -/// function2 backend for type erasure. -/// -/// Usable like: `unique_continuable` -template -using unique_continuable = typename detail::unique_trait_of< - Args... ->::continuable; - -/// Defines a non-copyable promise type which is using the -/// function2 backend for type erasure. -/// -/// Usable like: `promise` -template -using promise = typename detail::unique_trait_of< - Args... ->::promise; - -// TODO channel -// TODO sink - -// clang-format on -} // namespace cti +#include +#include #endif // CONTINUABLE_HPP_INCLUDED__ diff --git a/test/playground/CMakeLists.txt b/test/playground/CMakeLists.txt index 06c3cab..fd50079 100644 --- a/test/playground/CMakeLists.txt +++ b/test/playground/CMakeLists.txt @@ -1,6 +1,7 @@ set(LIB_SOURCES ${CMAKE_SOURCE_DIR}/include/continuable/continuable-api.hpp ${CMAKE_SOURCE_DIR}/include/continuable/continuable.hpp + ${CMAKE_SOURCE_DIR}/include/continuable/continuable-types.hpp ${CMAKE_SOURCE_DIR}/include/continuable/continuable-base.hpp ${CMAKE_SOURCE_DIR}/include/continuable/continuable-trait.hpp ${CMAKE_SOURCE_DIR}/include/continuable/continuable-promise-base.hpp