Question: ```
//a class template to do something to STL container
template<typename T/*should be a STL container*/,typename Ele/*the type of element*/>
struct foo{
T a_container_with_an_element(){
    T con;
    Ele e;
    con.push_back(++++e);
    return con;
}

```

As you can see, it's really foolish to put the element's type into templates' parameter because it's already contained in the container's type.

So, is there any magic to get the element's type out of T?

Lots of Thx :-)

Answer: 
If the container is a standard library container, the name of the element is an embedded name of the container as follows:

```
typedef typename T::value_type type;

```

The standard container's have a few standard names in them (for example, see [vector on cppreference](http://en.cppreference.com/w/cpp/container/vector)) and the [C++ standard](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf) §23.2.

```
X::value_type
X::reference
X::const_reference
X::iterator
X::const_iterator
X::difference_type
X::size_type

```
Every "*container*" in the standard library, tries to adhere to the [`Container` concept](http://en.cppreference.com/w/cpp/concept/Container). This concepts requires that, given a container `T`:

1. `T::value_type` is the type of the container element
2. `T::reference` is a reference type to the container element
3. `T::const_reference` is a constant reference type to the container element

In your specific example, you can extract the element type by:

```
template<typename Container>
struct foo {
Container a_container_with_an_element(){
    Container con;
    typename Container::value_type e;
    con.push_back(++++e);
    return con;
}

```