-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow chaining -> with pointer-like value types. * Remove default types. * Use last argument to construct the mutex. * Fix typo in license. * More readable file names. * Typo in readme. * New default locks. * Revert "Allow chaining -> with pointer-like value types." This reverts commit 2321c7d. * Clean-up. * Better specialization example. * Home-made index_sequence. * Fix auto return type. * readme revamp. * Fix typos. --------- Co-authored-by: Louis-Charles Caron <louis-charles.caron@sensefly.com>
- Loading branch information
1 parent
4c33c79
commit e1821a5
Showing
13 changed files
with
480 additions
and
611 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2019-2022 Louis-Charles Caron | ||
|
||
// This file is part of the safe library (https://github.com/LouisCharlesC/safe). | ||
|
||
// Use of this source code is governed by an MIT-style license that can be | ||
// found in the LICENSE file or at https://opensource.org/licenses/MIT. | ||
|
||
#pragma once | ||
|
||
#include <mutex> | ||
|
||
namespace safe | ||
{ | ||
namespace impl | ||
{ | ||
// Base template defining default lock types for all mutex types. | ||
// Specialize this template as shown in the ReadMe and tests to define your own default locks. | ||
// This struct only uses the first template parameter (MutexType), the parameter pack is there | ||
// only to allow one to partially specialize the template using a single template parameter. Doing | ||
// so overrides the default types for any MutexType. See the test_default_locks.cpp file for examples. | ||
template<typename MutexType, typename...> | ||
struct DefaultLocks | ||
{ | ||
using ReadOnly = std::lock_guard<MutexType>; | ||
using ReadWrite = std::lock_guard<MutexType>; | ||
}; | ||
} // namespace impl | ||
|
||
template<typename MutexType> | ||
using DefaultReadOnlyLockType = typename impl::DefaultLocks<MutexType>::ReadOnly; | ||
template<typename MutexType> | ||
using DefaultReadWriteLockType = typename impl::DefaultLocks<MutexType>::ReadWrite; | ||
} // namespace safe |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023 Louis-Charles Caron | ||
|
||
// This file is part of the safe library (https://github.com/LouisCharlesC/safe). | ||
|
||
// Use of this source code is governed by an MIT-style license that can be | ||
// found in the LICENSE file or at https://opensource.org/licenses/MIT. | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
|
||
namespace safe | ||
{ | ||
namespace impl | ||
{ | ||
// This set of template and specializations is used to extract the type of the last argument of a paramter pack. | ||
template <typename... Ts> struct Last; // Base template, specializations cover all uses. | ||
template <typename First, typename Second, typename... Others> struct Last<First, Second, Others...> | ||
{ | ||
using type = typename Last<Second, Others...>::type; | ||
}; | ||
template <typename T> struct Last<T> | ||
{ | ||
using type = T; | ||
}; | ||
template <> struct Last<> | ||
{ | ||
using type = void; | ||
}; | ||
|
||
template<std::size_t... Is> | ||
struct index_sequence {}; | ||
template<std::size_t N, std::size_t... Is> | ||
struct index_sequence<N, Is...> | ||
{ | ||
using type = typename index_sequence<N-1, N-1, Is...>::type; | ||
}; | ||
template<std::size_t... Is> | ||
struct index_sequence<0, Is...> | ||
{ | ||
using type = index_sequence<Is...>; | ||
}; | ||
|
||
template<std::size_t N> | ||
constexpr typename index_sequence<N>::type make_index_sequence() | ||
{ | ||
return {}; | ||
} | ||
} // namespace impl | ||
|
||
template <typename... Ts> using Last = typename impl::Last<Ts...>::type; | ||
} // namespace safe |
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
Oops, something went wrong.