# Trigger custom implicit conversion on "copy"

Is there anything horribly wrong with creating different representations of data behind the scenes when constructing a std::vector<T> from a std::vector<U>?

std::vector<Color> initialScene(Settings::HRes * Settings::VRes);

std::vector<Pixel> finalScene(std::begin(initialScene), std::end(initialScene));


With the Pixel(const Color&) constructor doing something along the lines of:

explicit Pixel(const Color& color) {
// Basically swaps blue and red channels
data[0] = color.blue;
data[1] = color.green;
data[2] = color.red;
}


Note: this is not exactly what the converting constructor does; it's more of an illustration.

## 1 Answer

No problem with that at all, since it's not the copy which is doing the conversion (which would be strange) but the constructor. Since the vector templates you've mentioned are clearly of different types, the operation you describe would not at all be unexpected. It's little different from using std::copy to read from a file into an STL container, which is a common idiom.