Boost logo

Ublas :

Subject: Re: [ublas] [boost] Is there a special reason to use inline before template functions?
From: Daryle Walker (darylew_at_[hidden])
Date: 2008-12-10 02:38:06


On Dec 7, 2008, at 6:48 PM, Thomas Klimpel wrote:

> in boost, many template functions (but not all) use inline.
> (Example from boost/accumulators/framework/accumulator_set.hpp that
> uses inline:
> template<typename Args>
> inline accumulator_visitor<Args> const make_accumulator_visitor
> (Args const &args)
> {
> return accumulator_visitor<Args>(args);
> }
>
> Example from boost/algorithm/minmax.hpp hat doesn't use inline:
> template <typename T>
> tuple< T const&, T const& >
> minmax(T const& a, T const& b) {
> return (b<a) ? make_tuple(cref(b),cref(a)) : make_tuple(cref
> (a),cref(b));
> }
> )
>
> Is there a special reason why inline is used for template
> functions? I would expect that current compilers know better when
> inlining a function provides a benefit than the programmer. So I
> guess there is a better reason for using the inline keyword before
> template function than just speculative performance optimization,
> but I can't figure it out. Can anybody help me?

Template stuff generally has to be defined in a header file ("export"
notwithstanding). My guideline for "inline" is whether or not I
would use for a particular function if that function had no template
stuff about it. (In other words, would I leave it "inline" in a
header or non-inline in a mandatory source file.)

>
> Most libs only prepend inline before template functions, but ublas
> prepends nearly every member function with the macro
> "BOOST_UBLAS_INLINE", which expands to "inline". Is there a reason
> why ublas uses this macro?

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com