Created
May 16, 2017 16:50
-
-
Save yaneury/4abf114af1ebf58669c5cba771be9618 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <type_traits> | |
| enum class AlignBy { | |
| Word, DoubleWord | |
| }; | |
| struct _AlignmentId; | |
| template <typename Id, typename T, T value> | |
| struct IntegralTemplateType : std::integral_constant<T, value> { | |
| using TypeId = Id; | |
| }; | |
| template <AlignBy ab> | |
| struct Alignment : IntegralTemplateType<_AlignmentId, AlignBy, ab> {}; | |
| template<typename D, typename... Args> | |
| struct _GetValue; | |
| template<typename D, typename T2, typename... Args> | |
| struct _GetValue<D, T2, Args...> { | |
| template<typename D2, typename T22, typename Enable = void> | |
| struct impl | |
| : std::integral_constant<decltype(D::value), _GetValue<D, Args...>::value> {}; | |
| template<typename D2, typename T22> | |
| struct impl <D2, T22, std::enable_if_t<std::is_same<typename D2::type_id, typename T22::type_id>::value>> | |
| : std::integral_constant<decltype(D::value), T22::value> {}; | |
| static constexpr const auto value = impl<D, T2>::value; | |
| }; | |
| template<typename D> | |
| struct _GetValue<D> : std::integral_constant<decltype(D::value), D::value> {}; | |
| template <typename ...Args> | |
| struct Allocator { | |
| static constexpr AlignBy _Alignment = _GetValue<Alignment<AlignBy::Word>, Args...>::value; | |
| }; | |
| int main() { | |
| using AllocType = Allocator< | |
| Alignment<AlignBy::Word> | |
| >; | |
| return static_cast<int>(AllocType::_Alignment); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment