Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the receiver CPOs (set_value, set_error, set_stopped) #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# CMakeLists.txt -*-cmake-*-
# ----------------------------------------------------------------------------
# Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
#
# 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.
# ----------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.14.0)
project(p2300 VERSION 0.1.0)

Expand Down Expand Up @@ -35,6 +60,9 @@ list(APPEND test_exposition_only

list(APPEND test_components
test/operation_state.cpp
test/set_error.cpp
test/set_stopped.cpp
test/set_value.cpp
test/start.cpp
test/tag_invoke.cpp
)
Expand All @@ -43,4 +71,4 @@ add_executable(p2300_test ${test_exposition_only} ${test_components})
target_link_libraries(p2300_test PUBLIC gtest_main)

include(GoogleTest)
gtest_discover_tests(p2300_test)
gtest_discover_tests(p2300_test)
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ can be reported on the [P2300 issue tracker](https://github.com/brycelelbach/wg2

## Concept Overview

This section is intended to yield an overview of the used concepts.
The primary purpose is to serve as a quick reference of what needs
to be implemented rather than necessarily capturing all details.

- `operation_state`

template <class S>
concept operation_state
= destructible<S>
&& is_object_v<S>
&& requires(S& s) { { execution::start(s) } noexcept; }
&& requires(S& s) { { <a href="#start-cpo">execution::start(s)</a> } noexcept; }
;

## Customization Point Object Overview

This section is intended to yield and overview of the user customization
point objects. The notation resembles how the customization points
can be called. It doesn't represent their respective implementation.
This section is intend as quick reference when implementing the
corresponding customization rather than necessarily capturing all
details.

- <a name="set_error-cpo">`set_error(auto&& receiver, auto&& error) noexcept -> void`</a>
- <a name="set_stopped-cpo">`set_stopped(auto&& receiver) noexcept -> void`</a>
- <a name="set_value-cpo">`set_value(auto&& receiver, auto&&... args) noexcept -> void`</a>
- <a name="start-cpo">`start(auto& state) noexcept -> void`</a>
5 changes: 4 additions & 1 deletion include/execution.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/execution.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -32,6 +32,9 @@

#include <execution>
#include <p2300/movable_value.hpp>
#include <p2300/set_error.hpp>
#include <p2300/set_stopped.hpp>
#include <p2300/set_value.hpp>
#include <p2300/start.hpp>
#include <p2300/operation_state.hpp>

Expand Down
2 changes: 1 addition & 1 deletion include/functional.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/functional.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion include/p2300/callable.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/p2300/callable.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion include/p2300/movable_value.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/p2300/moveable.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion include/p2300/non_associated.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/p2300/non_associated.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
57 changes: 57 additions & 0 deletions include/p2300/set_error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// include/p2300/set_error.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// 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 INCLUDED_INCLUDE_P2300_SET_ERROR
#define INCLUDED_INCLUDE_P2300_SET_ERROR

#include <functional>
#include <utility>

// ----------------------------------------------------------------------------

namespace std {
namespace _Set_error {
class _Cpo {
public:
template <class _Receiver, class _Error>
requires nothrow_tag_invocable<_Cpo, _Receiver, _Error>
auto operator()(_Receiver&& __receiver, _Error&& __error) const noexcept -> void
{
std::tag_invoke(*this, std::forward<_Receiver>(__receiver), std::forward<_Error>(__error));
}
};
}

namespace execution {
using set_error_t = _Set_error::_Cpo;
inline namespace _Cpos {
inline constexpr set_error_t set_error{};
}
}
}

// ----------------------------------------------------------------------------

#endif
58 changes: 58 additions & 0 deletions include/p2300/set_stopped.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// include/p2300/set_stopped.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// 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 INCLUDED_INCLUDE_P2300_SET_STOPPED
#define INCLUDED_INCLUDE_P2300_SET_STOPPED

#include <functional>
#include <utility>

// ----------------------------------------------------------------------------
// [exec.set_stopped]

namespace std {
namespace _Set_stopped {
class _Cpo {
public:
template <class _Receiver>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not go with receiver should we then constraint with movable-value?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe - that would need to go into the specification, though. The current specification just says "for some subexpression R" without adding any requirements on R. I believe the implementation allowing (and testing) the different lvalue overloads is as specified. An implementation not passing these tests does not match the specification.

requires nothrow_tag_invocable<_Cpo, _Receiver>
auto operator()(_Receiver&& __receiver) const noexcept -> void
{
std::tag_invoke(*this, std::forward<_Receiver>(__receiver));
}
};
}

namespace execution {
using set_stopped_t = _Set_stopped::_Cpo;
inline namespace _Cpos {
inline constexpr set_stopped_t set_stopped{};
}
}
}

// ----------------------------------------------------------------------------

#endif
58 changes: 58 additions & 0 deletions include/p2300/set_value.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// include/p2300/set_value.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// 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 INCLUDED_INCLUDE_P2300_SET_VALUE
#define INCLUDED_INCLUDE_P2300_SET_VALUE

#include <functional>
#include <utility>

// ----------------------------------------------------------------------------

namespace std {
namespace _Set_value {
class _Cpo {
public:
template <class _Receiver, class... _Args>
requires nothrow_tag_invocable<_Cpo, _Receiver, _Args...>
auto operator()(_Receiver&& __receiver, _Args&&... __args) const noexcept -> void
{
std::tag_invoke(*this, std::forward<_Receiver>(__receiver), std::forward<_Args>(__args)...);
}
};
}

namespace execution {
using set_value_t = _Set_value::_Cpo;
inline namespace _Cpos {
inline constexpr set_value_t set_value{};
}
}
}


// ----------------------------------------------------------------------------

#endif
2 changes: 1 addition & 1 deletion include/p2300/start.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace std {
&& std::is_lvalue_reference_v<_OperationState>
auto operator()(_OperationState&& __state) const noexcept -> void
{
tag_invoke(*this, __state);
std::tag_invoke(*this, __state);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/p2300/tag_invoke.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// include/p2300/tag_invoke.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion std-headers/functional
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// std-headers/functional -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
4 changes: 2 additions & 2 deletions test/call_result_t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// test/call_result_t.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -56,4 +56,4 @@ TEST(call_result_t, function_objects)
EXPECT_TRUE((P2300_std::is_same_v<P2300_call_result_t<decltype([](bool, double){}), bool, double>, void>));
EXPECT_TRUE((P2300_std::is_same_v<P2300_call_result_t<decltype([](auto v){ return v; }), bool>, bool>));
EXPECT_TRUE((P2300_std::is_same_v<P2300_call_result_t<decltype([](auto v){ return v; }), double>, double>));
}
}
4 changes: 2 additions & 2 deletions test/callable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// test/callable.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -60,4 +60,4 @@ TEST(callable, function_objects)
EXPECT_TRUE((P2300_callable<decltype([](int){}), short>));
EXPECT_TRUE((P2300_callable<decltype([](int){}), long>));
EXPECT_TRUE((P2300_callable<decltype([](int){}), long>));
}
}
2 changes: 1 addition & 1 deletion test/movable_value.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// test/movable_value.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion test/non_associated.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// test/non_associated.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
4 changes: 2 additions & 2 deletions test/nothrow_callable.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// test/nothrow_callable.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// Copyright (C) 2021 Dietmar Kuehl http://www.dietmar-kuehl.de
// Copyright (C) 2022 Dietmar Kuehl http://www.dietmar-kuehl.de
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -72,4 +72,4 @@ TEST(nothrow_callable, function_objects)
EXPECT_FALSE((P2300_nothrow_callable<decltype([](){})>));
EXPECT_TRUE((P2300_nothrow_callable<decltype([]() noexcept {})>));
EXPECT_FALSE((P2300_nothrow_callable<decltype([]() noexcept {}), int>));
}
}
Loading