[Rcpp-devel] What is the scope of a "using TYPE;" directive?

Douglas Bates bates at stat.wisc.edu
Fri Jul 29 23:20:46 CEST 2011


This is not directly an Rcpp question but it does relate to
programming style when using Rcpp.

I try to avoid statements like

using namespace Rcpp;

in a header file because that will change the visible names in any
other files that include this header.  The alternative, of course, is
many declarations with long names like


 Rcpp::NumericVector   foo(const Rcpp::IntegerVector&);

Lately I have taken to including statements of the form

namespace mynamespace {
    using Rcpp::NumericVector;
    using Rcpp::IntegerVector;

    NumericVector foo(const IntegerVector&);
}

so that I control exactly which names are exposed without qualifiers
and not expose the entire Rcpp namespace.

Can anyone tell me if that using declaration has effect only within
the declared namespace "mynamespace"?  That is what I want to have
happen so that by the end of the header file my temporary exposure of
names is no longer in effect.


More information about the Rcpp-devel mailing list