C++0x: Type determination

From Dwarf Wiki
Jump to: navigation, search

For detail description of the feature, please refer to:





The definition of a variable with an explicit initialization can use the auto keyword. This creates a variable of the specific type of the initializer.

auto x = 7;                  // x has type int
template<class T> void printall(const vector<T>& v)
  for (auto p = v.begin();   // p has type vector<T>::const_iterator
    cout << *p << "\n";

decltype can be used to compile-time determine the type of an expression.

const std::vector<int> v(1);
decltype(v[0]) b;   // b has type const int&, the return type of 
                    // std::vector<int>::operator[](size_type)

Proposed change to DWARF


auto and decltype are resolved to an actual type during compile time. DWARF type entries describes the actual type of the object.