Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Created March 25, 2018 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loliGothicK/8ca4765e24366654e8cd7cd9fc1a62d8 to your computer and use it in GitHub Desktop.
Save loliGothicK/8ca4765e24366654e8cd7cd9fc1a62d8 to your computer and use it in GitHub Desktop.
#include <type_traits>
#include <utility>
#include <iterator>
template < class Range >
typename std::enable_if<
std::is_same<
typename std::iterator_traits<typename std::decay<Range>::type>::iterator_category,
std::random_access_iterator_tag
>::value
>::type
func(Range&& range){
// Rangeはランダムラクセスイテレータを持つコンテナなので
// ランダムラクセスするアルゴリズムを記述できる
}
template < class Range >
typename std::enable_if<
!std::is_same<
typename std::iterator_traits<typename std::decay<Range>::type>::iterator_category,
std::random_access_iterator_tag
>::value
>::type
func(Range&& range){
// Rangeはランダムラクセスイテレータではないイテレータを持つコンテナなので
// ランダムラクセスなしでアルゴリズムを記述する
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment