c++ - Why use static function template? -
c++ - Why use static function template? -
i'm reading alex graves's rnnlib. in codes there many static function templates not class fellow member methods defined static
, while not.(see below)
some code snipplets of helpers.hpp
:
... // static template <class r> static void sort(r& r) { sort(boost::begin(r), boost::end(r)); } // static template <class r> static void reverse_sort(r& r) { sort(boost::rbegin(r), boost::rend(r)); } // non static template <class r> pair<typename range_value<r>::type, typename range_value<r>::type> minmax(const r& r) { pair<typename range_const_iterator<r>::type, typename range_const_iterator<r>::type> p = minmax_element(boost::begin(r), boost::end(r)); homecoming make_pair(*p.first, *p.second); } // static template <class r> static void bound_range (r& r, const typename boost::range_value<r>::type& minval, const typename boost::range_value<r>::type& maxval) { (typename range_iterator<r>::type = boost::begin(r); != boost::end(r); ++it) { *it = bound(*it, minval, maxval); } } ...
why of these global function templates defined static while not?
in context, static
keyword refers static linkage, i.e. function visible in translation unit it's defined.
now, beingness functions defined in header file, effect of static
keyword compiler generate code function in every translation unit include header file (and uses function). function, furthermore, inlined.
for template functions, i'd using static
, inline
or no keyword produce same result; in fact, in cases function inlined , no multiple definition error raised.
so, interesting question "why utilize static
on non-template functions".
c++ templates static
Comments
Post a Comment