#include <vector>
#include <utility>
#include <type_traits>
#include <iostream>
#include <iterator>
template <typename Iter>
using iter_val_t = typename std::iterator_traits< Iter >::value_type;
template <typename Iter, typename T>
constexpr bool is_T_iter_v = std::is_same< iter_val_t< Iter >, T >::value;
template <typename Iter>
constexpr bool is_wchar_iter_v = std::is_same< iter_val_t< Iter >, wchar_t >::value;
template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char >, int > = 0 >
void CalcSomething( Iter begin, Iter end )
{
std::cout << "i'm char\n";
}
template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char16_t > ||
( is_wchar_iter_v< Iter > && sizeof( wchar_t ) == sizeof( char16_t ) ), int > = 0 >
void CalcSomething( Iter begin, Iter end )
{
std::cout << "i'm char16\n";
}
template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char32_t > ||
( is_wchar_iter_v< Iter > && sizeof( wchar_t ) == sizeof( char32_t ) ), int > = 0 >
void CalcSomething( Iter begin, Iter end )
{
std::cout << "i'm char32\n";
}
int main()
{
const char arr[ 5 ] = {};
CalcSomething( std::begin( arr ), std::end( arr ) );
std::vector<char> v1;
CalcSomething( v1.begin(), v1.end() );
std::vector<char16_t> v2;
CalcSomething( v2.begin(), v2.end() );
std::vector<char32_t> v3;
CalcSomething( v3.begin(), v3.end() );
std::vector<wchar_t> v4;
CalcSomething( v4.begin(), v4.end() );
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHV0aWxpdHk+CiNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aXRlcmF0b3I+Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgSXRlcj4KdXNpbmcgaXRlcl92YWxfdCA9IHR5cGVuYW1lIHN0ZDo6aXRlcmF0b3JfdHJhaXRzPCBJdGVyID46OnZhbHVlX3R5cGU7Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgSXRlciwgdHlwZW5hbWUgVD4KY29uc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