Add missing type template parameter to EnableIfT
[alure.git] / include / AL / alure2-aliases.h
blobc21b897bbc3bdb2d60add619a4d66c340f2379c3
1 /*********
2 * Defines aliases for relevant STL containers. Be aware that even though these
3 * can be modified to use custom types, the library expects them to have
4 * standard APIs and semantics. Changing these aliases will also break ABI, so
5 * they should be left alone for shared builds unless all users are also
6 * rebuilt.
7 */
9 #ifndef AL_ALURE2_ALIASES_H
10 #define AL_ALURE2_ALIASES_H
12 #include <vector>
13 #include <string>
14 #include <memory>
15 #include <future>
16 #include <chrono>
17 #include <array>
19 namespace alure {
21 // Convenience aliases
22 template<typename T> using RemoveRefT = typename std::remove_reference<T>::type;
23 template<bool B, typename T=void> using EnableIfT = typename std::enable_if<B,T>::type;
26 // NOTE: Need to define this as a macro since we can't use the aliased type
27 // names for explicit template instantiation, and the whole purpose of these
28 // aliases is to avoid respecifying the desired implementation.
29 #define ALURE_SHARED_PTR_TYPE std::shared_ptr
32 // Duration in seconds, using double precision
33 using Seconds = std::chrono::duration<double>;
35 // A SharedPtr implementation, defaults to C++11's std::shared_ptr.
36 template<typename... Args> using SharedPtr = ALURE_SHARED_PTR_TYPE<Args...>;
37 template<typename T, typename... Args>
38 inline SharedPtr<T> MakeShared(Args&&... args)
39 { return std::make_shared<T>(std::forward<Args>(args)...); }
41 // A WeakPtr implementation, defaults to C++11's std::weak_ptr.
42 template<typename... Args> using WeakPtr = std::weak_ptr<Args...>;
44 // A UniquePtr implementation, defaults to C++11's std::unique_ptr.
45 template<typename... Args> using UniquePtr = std::unique_ptr<Args...>;
46 // Implement MakeUnique for single objects and arrays.
47 namespace _details {
48 template<typename T>
49 struct MakeUniq { using object = UniquePtr<T>; };
50 template<typename T>
51 struct MakeUniq<T[]> { using array = UniquePtr<T[]>; };
52 template<typename T, std::size_t N>
53 struct MakeUniq<T[N]> { struct invalid_type { }; };
54 } // namespace _details
55 // MakeUnique for a single object.
56 template<typename T, typename... Args>
57 inline typename _details::MakeUniq<T>::object MakeUnique(Args&&... args)
58 { return UniquePtr<T>(new T(std::forward<Args>(args)...)); }
59 // MakeUnique for an array.
60 template<typename T>
61 inline typename _details::MakeUniq<T>::array MakeUnique(std::size_t num)
62 { return UniquePtr<T>(new typename std::remove_extent<T>::type[num]()); }
63 // Disable MakeUnique for an array of declared size.
64 template<typename T, typename... Args>
65 inline typename _details::MakeUniq<T>::invalid_type MakeUnique(Args&&...) = delete;
67 // A Promise/Future (+SharedFuture) implementation, defaults to C++11's
68 // std::promise, std::future, and std::shared_future.
69 template<typename... Args> using Promise = std::promise<Args...>;
70 template<typename... Args> using Future = std::future<Args...>;
71 template<typename... Args> using SharedFuture = std::shared_future<Args...>;
73 // A Vector implementation, defaults to C++'s std::vector.
74 template<typename... Args> using Vector = std::vector<Args...>;
76 // A static-sized Array implementation, defaults to C++11's std::array.
77 template<typename T, std::size_t N> using Array = std::array<T, N>;
79 // A String implementation, default's to C++'s std::string.
80 template<typename... Args> using BasicString = std::basic_string<Args...>;
81 using String = BasicString<std::string::value_type>;
83 } // namespace alure
85 #endif /* AL_ALURE2_ALIASES_H */