Q:

C++: Is there a way to extract type out of instanced template?

//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 :-)

A:

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) and the C++ standard §23.2.
X::value_type
X::reference
X::const_reference
X::iterator
X::const_iterator
X::difference_type
X::size_type

A:

Every "container" in the standard library, tries to adhere to the Container concept. This concepts requires that, given a container T:

T::value_type is the type of the container element
T::reference is a reference type to the container element
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;
}

A:

In your special case where you know that T is a STL container Naill's  answer is correct, use the nested types in the container.
If however you want a more generic "I know I am getting a template as T and I want the type of the first parameter of that template" case you can get the type through template specialization:
template<typename T>
struct MyFirstElement;
template<template<typename...> class T_Container, typename T_Type, typename... Ts>
struct MyFirstElement<T_Container<T_Type,Ts...>>{
    using Type = T_Type;
};

//unit test
using MustBeInt = typename MyFirstElement<std::vector<int>>::Type;
using MustBeLong = typename MyFirstElement<std::map<long,float>>::Type;

static_assert(std::is_same<MustBeInt,int>::value,"");
static_assert(std::is_same<MustBeLong,long>::value,""); 

//this works too even though its not an STL container
template<typename T, typename U, typename Z>
struct MyCrazyContainer{};

static_assert(std::is_same<typename MyFirstElement<MyCrazyContainer<bool,long,float>>::Type,bool>::value,"");

here is a live example: http://ideone.com/OxhSOc
As Jarod42 pointed out this will only work with templates which are "regular" i.e. only have types as parameters. std::array for example breatks this because it has an int as a second parameter. 

