Simple-Utility v2.3.1
Loading...
Searching...
No Matches
Utility.hpp
Go to the documentation of this file.
1// Copyright Dominic Koepke 2019 - 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SL_UTILITY_FUNCTIONAL_UTILITY_HPP
7#define SL_UTILITY_FUNCTIONAL_UTILITY_HPP
8
9#pragma once
10
14
15#include <memory>
16#include <utility>
17
19{
32 template <class To>
33 inline constexpr auto as = envelop<Transform>(
34 []<class From>(From&& arg) constexpr noexcept(concepts::nothrow_explicitly_convertible_to<From, To>) -> To
35 {
36 static_assert(concepts::explicitly_convertible_to<From, To>, "Argument is not convertible to target type.");
37
38 return static_cast<To>(std::forward<From>(arg));
39 });
40
44 inline constexpr auto dereference = envelop<Transform>(
45 []<class T>(T&& arg) constexpr noexcept(noexcept(*std::declval<T>())) -> decltype(auto)
46 {
47 static_assert(concepts::dereferencable<T>, "Argument is not usable as operand of unary operator *.");
48
49 return *std::forward<T>(arg);
50 });
51
56 inline constexpr auto addressof = envelop<Transform>(
57 [](auto& arg) constexpr noexcept
58 {
59 static_assert(requires { { std::addressof(arg) } -> concepts::pointer; }, "Argument is not usable for std::addressof.");
60
61 return std::addressof(arg);
62 });
63
67}
68
69#endif
Determines whether a type can be used in unary operator * expressions.
Definition: operators.hpp:725
Checks whether a type is explicit convertible to another.
Definition: stl_extensions.hpp:164
Checks whether a type is explicit convertible to another and does not throw.
Definition: stl_extensions.hpp:177
Checks whether the T denotes a (possibly cv-qualified) pointer type.
Definition: stl_extensions.hpp:35
constexpr auto dereference
Functional object which dereferences the given argument and returns the result.
Definition: Utility.hpp:44
constexpr auto as
Functional object which converts the given argument to the target type via static_cast.
Definition: Utility.hpp:33
constexpr auto addressof
Functional object which returns the address of the given argument.
Definition: Utility.hpp:56
Definition: Utility.hpp:19