request is_range and is_range_of metafunction

Hi, I am a user of Boost.Range. I have a problem when I write a function. The function accept a char range, wchar_t range or it, and each have different implement, so I want to use enable_if: /// #include <boost/range.hpp> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_same.hpp> using namespace boost; template<typename CharRange> typename enable_if<is_same<typename range_value<CharRange>::type, char>
::type my_range_function(CharRange const &) { // for char }
template<typename CharRange> typename enable_if<is_same<typename range_value<CharRange>::type, wchar_t>
::type my_range_function(CharRange const &) { // for wchar_t }
void my_range_function(int) { // for int } int main() { my_range_function("char range"); my_range_function(L"wchar_t range"); my_range_function(1); } /// The code does not work because range_value<CharRange>::type is not lazy, so I hope there is an metafunction "is_range_of" could be used like this: /// #include <boost/range.hpp> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_same.hpp> using namespace boost; template<typename CharRange> typename enable_if<is_range_of<char, CharRange> >::type my_range_function(CharRange const &) { // for char } template<typename CharRange> typename enable_if<is_range_of<wchar_t, CharRange> >::type my_range_function(CharRange const &) { // for wchar_t } void my_range_function(int) { // for int } int main() { my_range_function("char range"); my_range_function(L"wchar_t range"); my_range_function(1); } /// However, I upload a implement for the feature.
participants (1)
-
Atry