|
Rcpp Version 0.9.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- 00002 /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ 00003 // 00004 // has_iterator.h: Rcpp R/C++ interface class library -- identify if a class has a nested iterator typedef 00005 // 00006 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois 00007 // 00008 // This file is part of Rcpp. 00009 // 00010 // Rcpp is free software: you can redistribute it and/or modify it 00011 // under the terms of the GNU General Public License as published by 00012 // the Free Software Foundation, either version 2 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // Rcpp is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>. 00022 00023 #ifndef Rcpp__traits__has_iterator__h 00024 #define Rcpp__traits__has_iterator__h 00025 00026 /* "inspired" from the tr1_impl/functional file 00027 This uses the SFINAE technique to identify if a class T has 00028 an iterator typedef 00029 */ 00030 00031 namespace Rcpp{ 00032 namespace traits{ 00033 00034 struct __sfinae_types { 00035 typedef char __one; 00036 typedef struct { char __arr[2]; } __two; 00037 }; 00038 00039 template<typename T> 00040 class _has_iterator_helper : __sfinae_types { 00041 template<typename U> struct _Wrap_type { }; 00042 00043 template<typename U> 00044 static __one __test(_Wrap_type<typename U::iterator>*); 00045 00046 template<typename U> 00047 static __two __test(...); 00048 00049 public: 00050 static const bool value = sizeof(__test<T>(0)) == 1; 00051 }; 00052 00053 template<typename T> 00054 class _is_importer_helper : __sfinae_types { 00055 template<typename U> struct _Wrap_type { }; 00056 00057 template<typename U> 00058 static __one __test(_Wrap_type<typename U::r_import_type>*); 00059 00060 template<typename U> 00061 static __two __test(...); 00062 00063 public: 00064 static const bool value = sizeof(__test<T>(0)) == 1; 00065 }; 00066 00067 template<typename T> 00068 class _is_generator_helper : __sfinae_types { 00069 template<typename U> struct _Wrap_type { }; 00070 00071 template<typename U> 00072 static __one __test(_Wrap_type<typename U::r_generator>*); 00073 00074 template<typename U> 00075 static __two __test(...); 00076 00077 public: 00078 static const bool value = sizeof(__test<T>(0)) == 1; 00079 }; 00080 00081 00082 template<typename T> 00083 class _is_exporter_helper : __sfinae_types { 00084 template<typename U> struct _Wrap_type { }; 00085 00086 template<typename U> 00087 static __one __test(_Wrap_type<typename U::r_export_type>*); 00088 00089 template<typename U> 00090 static __two __test(...); 00091 00092 public: 00093 static const bool value = sizeof(__test<T>(0)) == 1; 00094 }; 00095 00103 template<typename T> struct has_iterator : 00104 integral_constant<bool,_has_iterator_helper<T>::value> { }; 00105 00112 template<typename T> struct is_importer : 00113 integral_constant<bool,_is_importer_helper<T>::value> { }; 00114 00115 template<typename T> struct is_exporter : 00116 integral_constant<bool,_is_exporter_helper<T>::value> { }; 00117 00118 template<typename T> struct is_generator : 00119 integral_constant<bool,_is_generator_helper<T>::value> { }; 00120 00121 } // traits 00122 } // Rcpp 00123 00124 #endif