1) The C++0x standard is in its finalization stage. It's a bit late for new feature ideas.
2) Concepts, initializer lists and lambdas are all part of the next standard. Here's an idea of how your example would look there:
Code:
#include <iostream>
// This is actually defined by the standard library.
concept Container<typename C>
{
// Name various types associated with the container (with defaults).
typename value_type;
typename pointer = value_type*;
typename size_type = std::size_t;
// ...
typename iterator;
// A container's iterator must at least model ForwardIterator.
where ForwardIterator<iterator>;
// Some members are required.
size_type C::size() const;
iterator C::begin();
iterator C::end();
// and so on ...
};
template <class T>
class vector
{
public:
typedef T value_type;
// ...
// Initializer lists aren't finalized yet - no idea how they'll look.
vector(initializer_list<T> init_list)
{
for(int i = 0; i < init_list.length(); i++) // *5
{
T curr = init_list[i];
push_back(curr);
}
}
size_type size() { return m_end - m_start; }
// ...
};
// Tell the compiler that every vector is a Container.
template <typename T>
concept_map<Container<vector<T>>>
{
// It should all just fit.
}
template <Container C, UnaryFunction Fn>
requires Convertible<C::value_type, Fn::argument_type>,
Fn for_each(const C& arry, Fn func)
{
// Oh yeah, foreach loops are supported.
for(T &t : arry) {
func(t);
}
}
int main()
{
vector<int> nums = {2, 7, 1, 3, 4, 8};
for_each(nums, [] (v) { cout << v << endl; });
// The type of "[] (v) { cout << v << endl; }" is unspecified, but it fulfills the UnaryFunction
// concept and is thus callable.
}