solinject  1.0.0
C++17 Dependency Injection header-only library
Utils.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 
3 /*
4  * solinject - C++ Dependency Injection header-only library
5  * Copyright (C) 2022 SemperSolus0x3d
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
22 
23 #pragma once
24 #include <mutex>
25 #include <vector>
26 #include <type_traits>
27 
28 namespace sol::di::impl
29 {
31  class Empty
32  {
33  public:
35  Empty() {}
36 
43  template<class...TArgs>
44  Empty(const TArgs&...args) {}
45  };
46 
51  template<class T>
53  {
54  size_t newSize = destination.size() + source.size();
55 
56  destination.reserve(newSize);
57 
58  destination.insert(
59  destination.end(),
62  );
63  }
64 
70  template <class TMutex, bool isEnabled>
71  using DiscardableMutex = std::conditional_t<isEnabled, TMutex, Empty>;
72 
78  template <class TMutex, bool isEnabled>
79  using DiscardableLock = std::conditional_t<isEnabled, std::lock_guard<TMutex>, Empty>;
80 
86  template <bool isEnabled, class...TMutexes>
87  using DiscardableScopedLock = std::conditional_t<isEnabled, std::scoped_lock<TMutexes...>, Empty>;
88 }
sol::di::impl::Empty::Empty
Empty()
Default constructor.
Definition: Utils.hpp:35
sol::di::impl::DiscardableLock
std::conditional_t< isEnabled, std::lock_guard< TMutex >, Empty > DiscardableLock
Lock, which can be discarded in compile-time.
Definition: Utils.hpp:79
std::vector::reserve
T reserve(T... args)
std::vector
std::vector::size
T size(T... args)
sol::di::impl::DiscardableScopedLock
std::conditional_t< isEnabled, std::scoped_lock< TMutexes... >, Empty > DiscardableScopedLock
Scoped lock, which can be discarded in compile-time.
Definition: Utils.hpp:87
sol::di::impl::Empty
Empty class.
Definition: Utils.hpp:31
sol::di::impl::DiscardableMutex
std::conditional_t< isEnabled, TMutex, Empty > DiscardableMutex
Mutex, which can be discarded in compile-time.
Definition: Utils.hpp:71
sol::di::impl::Empty::Empty
Empty(const TArgs &...args)
Constructor, which takes any number of any arguments.
Definition: Utils.hpp:44
std::vector::begin
T begin(T... args)
std::vector::insert
T insert(T... args)
std::vector::end
T end(T... args)
std::make_move_iterator
T make_move_iterator(T... args)
sol::di::impl::ConcatenateVectors
void ConcatenateVectors(std::vector< T > &destination, std::vector< T > source)
Adds elements of a vector to the end of the other vector.
Definition: Utils.hpp:52