Kevin just posted an article on the Rcpp Gallery which is pretty close in spirit, it tests explicitly using the macros from R's API:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List do_stuff( List x_ ) {
List x = clone(x_);
for( List::iterator it = x.begin(); it != x.end(); ++it ) {
switch( TYPEOF(*it) ) {
case REALSXP: {
NumericVector tmp = as<NumericVector>(*it);
tmp = tmp * 2;
break;
}
case INTSXP: {
if( Rf_isFactor(*it) ) break; // factors have type INTSXP too
IntegerVector tmp = as<IntegerVector>(*it);
tmp = tmp + 1;
break;
}
default: {
stop("incompatible SEXP encountered;");
}
}
}
return x;
}