I need to convert a class written in C++ 0x to one which compiles in Visual studio 2008. The code uses std::initializer_list.
Following is the code
template <typename data_type>
class symmatrix
{
public:
typedef data_type value_type;
symmatrix(std::initializer_list<T> const& size, value_type ini = value_type())
: m_data(0), m_memory(false) { resize(size); *this = ini; }
}
has to be converted to old standard understood by VS 2008.
I am really struggling to change 100 lines of new C++ code to old C++. So, please help me.
Initializer List is used in initializing the data members of a class. The list of members to be initialized is indicated with constructor as a comma-separated list followed by a colon. Following is an example that uses the initializer list to initialize x and y of Point class.
Conclusion: All other things being equal, your code will run faster if you use initialization lists rather than assignment. Note: There is no performance difference if the type of x_ is some built-in/intrinsic type, such as int or char* or float.
An object of type std::initializer_list<T> is a lightweight proxy object that provides access to an array of objects of type const T .
The initializer list is used to directly initialize data members of a class. An initializer list starts after the constructor name and its parameters.
Instead of an initializer_list
you can choose to pass a pair of iterators. But you'll have to change client code as well.
If it is a well-written class, it's bound to have other constructors, such as the one I mentioned. In this case I'd recommend to just remove the overload that takes an initializer_list
. Client code may have to be changed as well, if it uses that constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With