/* * Copyright (c) Facebook, Inc. and its affiliates. * * 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. */ #pragma once #include #include #include #include namespace unifex { struct this_ {}; template inline constexpr bool is_this_v = false; template <> inline constexpr bool is_this_v = true; template <> inline constexpr bool is_this_v = true; template <> inline constexpr bool is_this_v = true; template <> inline constexpr bool is_this_v = true; template <> inline constexpr bool is_this_v = true; template <> inline constexpr bool is_this_v = true; template struct _replace_this; template <> struct _replace_this { template using apply = Arg; template static Arg&& get(Arg&& arg, _ignore) noexcept { return (Arg &&) arg; } }; template <> struct _replace_this { template using apply = T; template static T&& get(_ignore, T& obj) noexcept { return (T &&) obj; } }; template <> struct _replace_this { template using apply = T&; template static T& get(_ignore, T& obj) noexcept { return obj; } }; template <> struct _replace_this { template using apply = T&&; template static T&& get(_ignore, T& obj) noexcept { return (T &&) obj; } }; template <> struct _replace_this { template using apply = const T&; template static const T& get(_ignore, T& obj) noexcept { return obj; } }; template <> struct _replace_this { template using type = const T&&; template static const T&& get(_ignore, T& obj) noexcept { return (const T&&) obj; } }; template using _normalize_t = conditional_t, Arg, void>; template using replace_this = _replace_this<_normalize_t>; template using replace_this_t = typename replace_this::template apply; template using replace_this_with_void_ptr_t = conditional_t, void*, Arg>; template struct _extract_this { template TFirst&& operator()(TFirst&& first, TRest&&...) const noexcept { return (TFirst&&) first; } }; template struct _extract_this { template decltype(auto) operator()(_ignore, TRest&&... rest) const noexcept { static_assert(sizeof...(IsThis) > 0, "Arguments to extract_this"); return _extract_this{}((TRest &&) rest...); } }; template using extract_this = _extract_this...>; } // namespace unifex #include