This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::shared_ptr<Locking<X>> yy(std::make_shared<Locking<X>>(X{})); | |
(*yy.get())->f(msg); | |
// This is most likely unsafe, since we can only lock a single copy of the pointer | |
Locking<std::shared_ptr<X>> xx(std::make_shared<X>()); | |
xx->get()->f(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class X | |
{ | |
int i = 0; | |
public: | |
int f(const char *msg) const | |
{ | |
return i++; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class U> class CallProxy | |
{ | |
U *_p; | |
std::recursive_mutex &_mtx; | |
mutable bool _own; | |
public: | |
CallProxy(U *pp, std::mutex &mtx) : _p(pp), _mtx(mtx), _own(true) | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> class Locking | |
{ | |
T _data; | |
mutable std::recursive_mutex _mtx; | |
/* Define call proxy here */ | |
public: | |
template <class U> Locking(U &&data) : _data(std::forward<U>(data)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> class Locking | |
{ | |
T _data; | |
mutable std::recursive_mutex _mtx; | |
template <class U> class CallProxy | |
{ | |
U *_p; | |
std::recursive_mutex &_mtx; | |
mutable bool _own; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, class Tuple, std::size_t I = 0> | |
consteval std::size_t TypeIndex() { | |
if constexpr (I >= std::tuple_size<Tuple>::value) { | |
return 0; | |
} else if constexpr (std::is_same_v<T, std::tuple_element_t<I, Tuple>>) { | |
return I + 1; | |
} else { | |
return TypeIndex<T, Tuple, I + 1>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type_index<int, std::tuple<char, int, float>>::value; | |
// Our type^^^ is found at index ^^^ 1 of our tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T, std::size_t I, class Tuple> // 1 | |
constexpr bool match_v = std::is_same_v<T, std::tuple_element_t<I, Tuple>>; | |
template <class T, class Tuple, // 2 | |
class Idxs = std::make_index_sequence<std::tuple_size_v<Tuple>>> | |
struct type_index; | |
template <class T, template <class...> class Tuple, class... Args, // 3 | |
std::size_t... Is> | |
struct type_index<T, Tuple<Args...>, std::index_sequence<Is...>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace std | |
{ | |
// 1. provide tuple_element<I, sorted_view<...>>::type | |
template <std::size_t I, class... Types> | |
struct tuple_element<I, utl::sorted_view<Types...>> | |
{ | |
using sorted_view_t = utl::sorted_view<Types...>; | |
using type = typename sorted_view_t::template tuple_element_t<I>; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sv.multi_sort<6, 4, 5>([](auto&& a, auto&& b) { return a > b; }); | |
auto [sName1, sName2, sSport, sGoldM, sSilverM, sBronzeM, sTotalM] = sv; | |
for (size_t i = 0; i < sv.size<6>(); i++) | |
{ | |
std::cout << sTotalM[i] << " " << sGoldM[i] << " " << sSilverM[i] << " " | |
<< sName1[i] << " " << sName2[i] << std::endl; | |
} |
NewerOlder