
Hi, i had this little idea. when yo want to customize a class with a container like template <typename T, typename Container> struct Foo; then you must instanciate it with: Foo<int, std::vector<int> > the second int is redundant. --- Alternative: template <typename T, template <typename, typename> class Container> struct Foo; Here i do not have an allocator for the instantiation of Container. --- What i would like is: template <typename T, typename Container> struct Foo { typedef typename mpl::apply<Container, T>::type foo; }; and instantiate it with: Foo<int, mpl::stl_foo::vector<mpl::placeholder::_1> > For that i need namespace boost::mpl::stl_foo { template <typename T, typename Alloc> struct vector { typedef std::vector<T, Alloc> type }; } so i can curry containers as i wish. just an idea

Sascha Krissler wrote:
What i would like is:
template <typename T, typename Container> struct Foo { typedef typename mpl::apply<Container, T>::type foo; };
and instantiate it with:
Foo<int, mpl::stl_foo::vector<mpl::placeholder::_1> >
For that i need
namespace boost::mpl::stl_foo { template <typename T, typename Alloc> struct vector { typedef std::vector<T, Alloc> type }; }
so i can curry containers as i wish.
just an idea
Try this instead: using mpl::_; Foo< int, std::vector<_> > :-) -- Eric Niebler Boost Consulting www.boost-consulting.com

On Sat, Nov 11, 2006 at 06:16:26PM -0800, Eric Niebler wrote:
Sascha Krissler wrote:
What i would like is:
template <typename T, typename Container> struct Foo { typedef typename mpl::apply<Container, T>::type foo; };
and instantiate it with:
Foo<int, mpl::stl_foo::vector<mpl::placeholder::_1> >
For that i need
namespace boost::mpl::stl_foo { template <typename T, typename Alloc> struct vector { typedef std::vector<T, Alloc> type }; }
so i can curry containers as i wish.
just an idea
Try this instead:
using mpl::_; Foo< int, std::vector<_> >
:-)
std::vector is not a metafunction, it has no ::type

Sascha Krissler <boost-dev <at> k.datenfreihafen.de> writes:
On Sat, Nov 11, 2006 at 06:16:26PM -0800, Eric Niebler wrote:
Sascha Krissler wrote:
std::vector is not a metafunction, it has no ::type
It will be if you wrap it with mpl::lambda(e.g. mpl::lambda<Container>, see mpl reference for details). :)

Sascha Krissler wrote:
On Sat, Nov 11, 2006 at 06:16:26PM -0800, Eric Niebler wrote:
Sascha Krissler wrote:
What i would like is:
template <typename T, typename Container> struct Foo { typedef typename mpl::apply<Container, T>::type foo; };
and instantiate it with:
Foo<int, mpl::stl_foo::vector<mpl::placeholder::_1> >
For that i need
namespace boost::mpl::stl_foo { template <typename T, typename Alloc> struct vector { typedef std::vector<T, Alloc> type }; }
so i can curry containers as i wish.
just an idea
Try this instead:
using mpl::_; Foo< int, std::vector<_> >
:-)
std::vector is not a metafunction, it has no ::type
It doesn't matter. Try it and see. -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler <eric@boost-consulting.com> writes:
std::vector is not a metafunction, it has no ::type
It doesn't matter. Try it and see.
I know Eric knows this, but for everyone else: that's not an implementation artifact, but a deliberately-designed feature. see http://boost-consulting.com/mplbook/metafunctions.html#lambda-and-non-metafu... -- Dave Abrahams Boost Consulting www.boost-consulting.com

On 11/11/06 9:10 PM, "Sascha Krissler" <boost-dev@k.datenfreihafen.de> wrote:
i had this little idea. when yo want to customize a class with a container like
template <typename T, typename Container> struct Foo;
then you must instanciate it with:
Foo<int, std::vector<int> >
the second int is redundant. [TRUNCATE failed solution with a template-based template parameter and a better solution with MPL reading or writing template parameters]
No, it's not redundant. STL stuff involving containers is set up so a direct, non-template, class can be used as a container. Solutions involving certain template games will break that philosophy. I use asserts to make sure a container is compliant with what I need. Here is an example from some code I'm putting in the Sandbox: //======================================================================== #include <memory> // for std::allocator #include <boost/type_traits/is_same.hpp> // for boost::is_same #include <boost/static_assert.hpp> // for BOOST_STATIC_ASSERT namespace boost { namespace math { //... template < int Radix, class Allocator = ::std::allocator<int> > class big_radix_whole { // Pre-conditions // (SNIP constraints on "Radix") BOOST_STATIC_ASSERT( (is_same<int, typename Allocator::value_type>::value) ); // ... }; //... } } //======================================================================== Now I can use a non-template allocator class like: //======================================================================== #include <cstddef> class my_int_allocator // Note: _no_ "template" preamble! { public: typedef int value_type; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef int * pointer; typedef int const * const_pointer; typedef int & reference; typedef int const & const_reference; // You're screwed if you need "rebind". // Put address, max_size, allocate, deallocate, etc. here... }; //======================================================================== -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
participants (5)
-
Daryle Walker
-
David Abrahams
-
Eric Niebler
-
pongba
-
Sascha Krissler