John Harrison wrote in news: in
comp.lang.c++:
> I want to write a templated constructor with a non-type template
> argument, like this.
>
> class X
> {
> public:
> X() : val(0) {}
>
> template <int I>
> X(X const&, X const&) : val(I) {}
>
> private:
> int val;
> };
>
> This compiles but I have no idea how to 'call' this constructor. Is it
> possible?
>
No.
> (Essentially I have a single algorithm to construct an X from two
> other X's and I would like to customise that algorithm at compile time
> using an integer parameter).
>
Wrap the integer up in a type, say boost::mpl::int_<> if you have
boost (*)
eg:
template < int I >
struct int_
{
};
your ctor becomes:
tempalte < int I >
X( X const&, X const&, int_< I > const & /* unused */)
: val( I )
{
}
usage:
int main()
{
X a, b, x( a , b, int_< 1 >() );
}
HTH.
*) boost::mpl ->
http://www.boost.org/libs/mpl/doc/
Rob.
--
http://www.victim-prime.dsl.pipex.com/