Skip to content

Instantly share code, notes, and snippets.

@FuZer
Last active February 17, 2019 22:27
Show Gist options
  • Select an option

  • Save FuZer/8681b5be993963e19063b84e8a47a9b6 to your computer and use it in GitHub Desktop.

Select an option

Save FuZer/8681b5be993963e19063b84e8a47a9b6 to your computer and use it in GitHub Desktop.
get Template 명시, enable_if_t 제거
#include <iostream>
template <std::size_t Idx>
struct A {
constexpr static std::size_t idx = Idx;
template <std::size_t Target>
using get = std::conditional_t<Target == 0, A<Idx>, typename A<idx-1>::template get<Target-1>>;
};
template <>
struct A<0> {
constexpr static std::size_t idx = 0;
template <std::size_t Target>
using get = A<0>;
};
int main() {
std::cout << A<10>::get<4>::idx << std::endl; // print 6
}
@FuZer
Copy link
Author

FuZer commented Feb 17, 2019

using get = A<0>;

이부분은 목적에 맞게 변경하면 될듯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment