Skip to content
Merged
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
4 changes: 3 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function(def_example example)
split(${example} target source)
add_executable(${target} ${source})
target_compile_options(${target} PUBLIC
$<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized>) # warnings being emitted from stdlib headers, why?
$<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized> # warnings being emitted from stdlib headers, why?
$<$<CXX_COMPILER_ID:Clang>:-Wno-gnu-line-marker>
)
target_link_libraries(${target}
PRIVATE STDEXEC::stdexec
stdexec_executable_flags
Expand Down
21 changes: 17 additions & 4 deletions include/stdexec/__detail/__domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,23 @@ namespace STDEXEC

// Common domain for a set of domains
template <class... _Domains>
struct __common_domain
constexpr auto __common_domain_fn() noexcept
{
using __t = __minvoke<__mtry_catch_q<std::common_type_t, __qq<__make_domain_t>>, _Domains...>;
};
if constexpr (__minvocable_q<std::common_type_t, _Domains...>)
{
return std::common_type_t<_Domains...>{};
}
// NOT TO SPEC: If each domain in Domains... is convertible to default_domain, then
// the common domain is default_domain.
else if constexpr (__minvocable_q<std::common_type_t, default_domain, _Domains...>)
{
return std::common_type_t<default_domain, _Domains...>{};
}
else
{
return __make_domain_t<_Domains...>{};
}
}
} // namespace __detail

////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -169,7 +182,7 @@ namespace STDEXEC
using __completion_domain_of_t = __completion_domain_t<_Tag, env_of_t<_Sender>, _Env const &...>;

template <class... _Domains>
using __common_domain_t = __t<__detail::__common_domain<_Domains...>>;
using __common_domain_t = decltype(__detail::__common_domain_fn<_Domains...>());

template <class... _Domains>
concept __has_common_domain =
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(stdexec_test_sources
stdexec/algos/consumers/test_sync_wait.cpp
stdexec/algos/consumers/test_spawn.cpp
stdexec/detail/test_any.cpp
stdexec/detail/test_common_domain.cpp
stdexec/detail/test_completion_signatures.cpp
stdexec/detail/test_demangle.cpp
stdexec/detail/test_utility.cpp
Expand Down Expand Up @@ -99,6 +100,7 @@ target_compile_definitions(common_test_settings INTERFACE
target_compile_options(common_test_settings INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/wd4714> # function marked as __forceinline not inlined
$<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized> # warnings being emitted from stdlib headers, why?
$<$<CXX_COMPILER_ID:Clang>:-Wno-gnu-line-marker>
)
target_link_libraries(common_test_settings INTERFACE $<TARGET_NAME_IF_EXISTS:TBB::tbb>)
# target_compile_definitions(
Expand Down
51 changes: 51 additions & 0 deletions test/stdexec/detail/test_common_domain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2022 Lucian Radu Teodorescu
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <catch2/catch_all.hpp>
#include <stdexec/execution.hpp>

#include <test_common/receivers.hpp>

namespace ex = STDEXEC;

namespace
{
struct gpu_domain
{};

struct thread_pool_domain : ex::default_domain
{};

struct parallel_runtime_domain : ex::default_domain
{};

template <class... Domains>
using common_domain_t = ex::__common_domain_t<Domains...>;

TEST_CASE("finding common domains", "[detail][domain]")
{
using common1 = common_domain_t<gpu_domain, gpu_domain>;
STATIC_REQUIRE(std::same_as<common1, gpu_domain>);

using common2 = common_domain_t<thread_pool_domain, parallel_runtime_domain>;
STATIC_REQUIRE(std::same_as<common2, ex::default_domain>);

using common3 = common_domain_t<gpu_domain, thread_pool_domain>;
STATIC_REQUIRE(
std::same_as<common3, ex::indeterminate_domain<gpu_domain, thread_pool_domain>>
|| std::same_as<common3, ex::indeterminate_domain<thread_pool_domain, gpu_domain>>);
}
} // namespace
Loading