I have a class X, which I provide a snippet of here:
class X {
public:
template
X(Iter begin, Iter end) : mVec(begin, end) {}
1) I would like to preserve the const on mVec, so that it is considered constant throughout the other methods of X.
This is a curious use of const
on a member variable. And it defies good design. By definition, construction is a process which requires the object to change.
As for your requirement to keep the object non-modifiable -- use proper encapsulation. You should use const
-member functions to expose any functionality based on your mVec
for the clients of your class.
2) I would like to avoid unnecessary copies if at all possible. That is, one solution is to have a static method that constructs a non-const temporary to range 1, inserts range 2 and returns it, and then define the concatenating constructor to
You should be looking at move-constructors and r-value references in general (a promised goal of C++0x). Read this article.