Boost logo

Boost :

Subject: Re: [boost] Generic type inferencer function?
From: Stefan Seefeld (stefan_at_[hidden])
Date: 2015-12-18 11:37:18


On 18.12.2015 11:20, Nat Goodspeed wrote:
> Our code has any number of instances of this pattern:
>
> template <typename T, typename U>
> class SomeTemplate
> {
> SomeTemplate(const T& t, const U& u);
> ...
> };
>
> template <typename T, typename U>
> SomeTemplate<T, U> make_SomeTemplate(const T& t, const U& u)
> {
> return SomeTemplate<T, U>(t, u);
> }
>
> Am I overlooking a generic boost::make<something>() of this general form?
>
> template <template<typename...> class CLASS_TEMPLATE, typename... ARGS>
> CLASS_TEMPLATE<ARGS...> make(ARGS && ... args)
> {
> return CLASS_TEMPLATE<ARGS...>(std::forward<ARGS>(args)...);
> }
>
> If that doesn't already exist... would it be useful to add (a less
> naive version) somewhere?

Given the small amount of code potentially to be reused, what would be
the advantage of having a generic version ? The goal of abstraction
should be clarity, but more often than not, generalizing code rips off
not only unnecessary details but also its meaning, making the code
harder, not easier, to understand.

        Stefan

-- 
      ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk