.. _program_listing_file_include_beluga_primitives.hpp: Program Listing for File primitives.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/beluga/primitives.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2023-2024 Ekumen, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // 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. #ifndef BELUGA_PRIMITIVES_HPP #define BELUGA_PRIMITIVES_HPP #include #include #include #include #include namespace beluga { using Weight = Numeric; using Cluster = Numeric; namespace state_detail { template struct has_member_variable_state : std::false_type {}; template struct has_member_variable_state().state)>> : std::true_type {}; template inline constexpr bool has_member_variable_state_v = has_member_variable_state::value; template struct has_member_state : std::false_type {}; template struct has_member_state().state())>> : std::true_type {}; template inline constexpr bool has_member_state_v = has_member_state::value; template struct has_non_member_state : std::false_type {}; template struct has_non_member_state()))>> : std::true_type {}; template inline constexpr bool has_non_member_state_v = has_non_member_state::value; struct state_fn { template < class T, std::enable_if_t< std::conjunction_v< has_member_variable_state, // std::negation>, // std::negation>>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept { return beluga::forward_like(t.state); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // has_member_state, // std::negation>>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::forward(t).state())) { return std::forward(t).state(); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // std::negation>, // has_non_member_state>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(state(std::forward(t)))) { return state(std::forward(t)); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // std::negation>, // std::negation>, // is_tuple_like>, int> = 0, std::enable_if_t<(std::tuple_size_v> > 1), int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::get<0>(std::forward(t)))) { return std::get<0>(std::forward(t)); } }; } // namespace state_detail inline constexpr state_detail::state_fn state; namespace weight_detail { template struct has_member_variable_weight : std::false_type {}; template struct has_member_variable_weight().weight)>> : std::true_type {}; template inline constexpr bool has_member_variable_weight_v = has_member_variable_weight::value; template struct has_member_weight : std::false_type {}; template struct has_member_weight().weight())>> : std::true_type {}; template inline constexpr bool has_member_weight_v = has_member_weight::value; template struct has_non_member_weight : std::false_type {}; template struct has_non_member_weight()))>> : std::true_type {}; template inline constexpr bool has_non_member_weight_v = has_non_member_weight::value; struct weight_fn { template < class T, std::enable_if_t< std::conjunction_v< has_member_variable_weight, // std::negation>, // std::negation>>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept { return beluga::forward_like(t.weight); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // has_member_weight, // std::negation>>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(std::forward(t).weight())) { return std::forward(t).weight(); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // std::negation>, // has_non_member_weight>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(weight(std::forward(t)))) { return weight(std::forward(t)); } template < class T, std::enable_if_t< std::conjunction_v< std::negation>, // std::negation>, // std::negation>, // is_tuple_like, // has_single_element>>, int> = 0> constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(element(std::forward(t)))) { return element(std::forward(t)); } }; } // namespace weight_detail inline constexpr weight_detail::weight_fn weight; } // namespace beluga #endif