
Matt Calabrese wrote:
On Tue, May 31, 2011 at 6:35 PM, lcaminiti <lorcaminiti@gmail.com> wrote:
For example? (Just so I understand this case correctly.)
////////// CONTRACT_FUNCTION( 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 <boost/type_traits.hpp> #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 ) { vector.push_back(element); } int main() { std::vector<int> v; // push_back(v, -1); // Error: Can't deduce vector type via IDENTITY_TYPE. push_back< int, std::allocator<int> >(v, -1); // OK but no type deduction :(( std::cout << v[0] << std::endl; return 0; } Questions: 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! --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/contract-syntax-redesign-tp3563993p356591... Sent from the Boost - Dev mailing list archive at Nabble.com.