header_utils
Loading...
Searching...
No Matches
with_sl.h
1
4
5#pragma once
6
7#include <concepts>
8#include "source_location.h"
9#include "hashes.h"
10
11#if !defined(__cpp_concepts)
12#error "This library requires concepts"
13#endif
14
15#ifdef __INTELLISENSE__
16#define EQ_SOURCE_LOCATION = source_location{}
17#else
18#define EQ_SOURCE_LOCATION = source_location::current()
19#endif
20
21namespace ghassanpl
22{
23
37
39 template <typename T>
40 struct with_sl
41 {
42 T Object;
43 source_location Location;
44
45 template <typename U>
46 requires (!std::same_as<std::remove_cvref_t<U>, with_sl<T>>)
47 with_sl(U&& u, source_location loc EQ_SOURCE_LOCATION)
48 : Object(std::forward<U>(u)), Location(std::move(loc))
49 {
50 }
51
52 with_sl(with_sl const& other) noexcept = default;
53 with_sl(with_sl&& other) noexcept = default;
54 with_sl& operator=(with_sl const& other) noexcept = default;
55 with_sl& operator=(with_sl&& other) noexcept = default;
56 };
57
60 template <typename T, typename HASH_FUNC = crc64_hasher>
61 struct with_slh
62 {
63 using hash_func = HASH_FUNC;
64 using hash_type = decltype(HASH_FUNC{}(source_location{}));
65
66 T Object;
67 hash_type LocationHash;
68
69 template <typename U>
70 requires (!std::same_as<std::remove_cvref_t<U>, with_slh<T>>)
72 with_slh(U&& t, hash_type loc = {})
73#else
74 with_slh(U&& t, hash_type loc = HASH_FUNC{}(source_location::current()))
75#endif
76 : Object(std::forward<U>(t)), LocationHash(loc)
77 {
78 }
79
80 with_slh(with_slh const& other) noexcept = default;
81 with_slh(with_slh&& other) noexcept = default;
82 with_slh& operator=(with_slh const& other) noexcept = default;
83 with_slh& operator=(with_slh&& other) noexcept = default;
84 };
85
87}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
Primary namespace for everything in this library.
Definition align+rec2.h:10
Use as a function parameter type to capture both the parameter and the call-site source location.
Definition with_sl.h:41
Use as a function parameter type to capture both the parameter and the hash of the call-site source l...
Definition with_sl.h:62