Boost logo

Boost :

Subject: [boost] [parameter] Preventing instantiation of lazy binding operator() until default is needed
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2009-05-29 14:08:31

This is a subset of my previous email, with a more specific and concrete
example. The following code:

#include <boost/parameter/name.hpp>
#include <boost/parameter/binding.hpp>


template <typename T> struct s {};

template <typename T>
struct bogus {
   typedef typename s<T>::type result_type;
   template <typename U> struct result: public s<U> {};
   result_type operator()() const {return 0;}

template <typename ArgPack>
void f(const ArgPack& ap) {
   const char* cs = ap[_my_param || bogus<const char*>()];

int main(int, char**) {
   f(_my_param = "foo");
   return 0;

does not work because result_type is invalid when the struct bogus is
instantiated when creating the default value used in operator||(). If
operator()() was a template, I think the compiler would delay
instantiating it until it was called. Is there a way to force
operator()() to be a template in Boost.Parameter, allowing its return type
to only be instantiated when Boost.Parameter knows that the default will
be used? This is a simplified example from a larger piece of code where
the lazy default does not have a valid return type in some cases, and the
parameter must be explicitly specified in those cases. Thank you.

-- Jeremiah Willcock

Boost list run by bdawes at, gregod at, cpdaniel at, john at