Simple-Utility v2.3.1
Loading...
Searching...
No Matches
CRTPBase.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 SIMPLE_UTILITY_CRTP_BASE_HPP
7#define SIMPLE_UTILITY_CRTP_BASE_HPP
8
9#pragma once
10
12
13namespace sl
14{
20 template <concepts::unqualified Derived, class Disambiguity = void>
22 {
23 protected:
28 [[nodiscard]]
29 constexpr const Derived& derived() const noexcept
30 {
31 return static_cast<const Derived&>(*this);
32 }
33
38 [[nodiscard]]
39 constexpr Derived& derived() noexcept
40 {
41 return static_cast<Derived&>(*this);
42 }
43
47 constexpr CRTPBase() noexcept
48 {
49 static_assert(std::is_base_of_v<CRTPBase, Derived>, "Derived doesn't inherit from CRTPBase.");
50 }
51
55 CRTPBase(const CRTPBase&) = default;
56
60 CRTPBase& operator =(const CRTPBase&) = default;
61
65 CRTPBase(CRTPBase&&) = default;
66
71
75 ~CRTPBase() = default;
76
81 [[nodiscard]]
82 constexpr bool operator ==(const CRTPBase&) const noexcept = default;
83 };
84}
85
86#endif
Utility type, which can be used as a base class for the crtp pattern.
Definition: CRTPBase.hpp:22
~CRTPBase()=default
Defaulted destructor.
CRTPBase & operator=(const CRTPBase &)=default
Defaulted copy-assignment operator.
CRTPBase(const CRTPBase &)=default
Defaulted copy-constructor.
constexpr const Derived & derived() const noexcept
Up-casts the this pointer to a const lvalue reference to Derived.
Definition: CRTPBase.hpp:29
constexpr Derived & derived() noexcept
Up-casts the this pointer to a lvalue reference to Derived.
Definition: CRTPBase.hpp:39
CRTPBase(CRTPBase &&)=default
Defaulted move-constructor.
constexpr bool operator==(const CRTPBase &) const noexcept=default
Defaulted equality operator.
constexpr CRTPBase() noexcept
Default constructor, performing compile-time checks.
Definition: CRTPBase.hpp:47
Definition: operators.hpp:15