Boost logo

Boost :

Subject: Re: [boost] [contract] syntax redesign
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-06-01 10:01:59

Matt Calabrese wrote:
> On Tue, May 31, 2011 at 6:35 PM, lcaminiti <lorcaminiti_at_[hidden]>
> wrote:
>> For example? (Just so I understand this case correctly.)
> //////////
> public template( class T, class Alloc )
> void (push_back)( (BOOST_IDENTITY_TYPE((std::vector< T, Alloc >&)))
> vector_,
> (const T&) element ) {
> vector_.push_back(element);
> }
> //////////
> In the above case, since the first parameter type actually ends up being
> the
> result of a metafunction invocation, you can't simply call the function by
> doing this_.push_back( an_instance_of_std_vector, 4 ). T and Alloc can no
> longer be deduced.

Yes, I see:

#include &lt;boost/type_traits.hpp&gt;
#include <memory>
#include <vector>
#include <iostream>

#define IDENTITY_TYPE(paren_type) \
    boost::function_traits< void paren_type >::arg1_type

template< typename T, class Alloc >
void push_back(
        // comma in type is now wrapped in parenthesis (ok for macros)
        typename IDENTITY_TYPE((std::vector< T, Alloc >&)) vector,
        const T& element ) {

int main() {
    std::vector<int> v;
// push_back(v, -1); // Error: Can't deduce vector type via
    push_back< int, std::allocator<int> >(v, -1); // OK but no type
deduction :((
    std::cout << v[0] << std::endl;

    return 0;

1) How bad is this? I am afraid that giving up this kind of automatic type
deduction makes generic programming less convenient... am I right? ( I'm not
a generic programmer ;) )
2) Does anyone know of a better way to handle commas within macro parameter
types but without using variadics?

Note: Because of this I will try to provide a different implementation of
IDENTITY_TYPE when variadics are supported (however, to properly handle the
types with commas I think that not just IDENTITY_TYPE but also the CONTRACT
macros need to modified to be aware that the type if a pp tuple). The same
applies to Boost.Local macros.

Thanks a lot!

View this message in context:
Sent from the Boost - Dev mailing list archive at

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