Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate C++ comment #1

Open
red-robby opened this issue Feb 6, 2023 · 0 comments
Open

Inaccurate C++ comment #1

red-robby opened this issue Feb 6, 2023 · 0 comments

Comments

@red-robby
Copy link

red-robby commented Feb 6, 2023

The file src/texture.h includes the lines (43-45),

// A fancy C++11 feature. emplace_back constructs the element in place,
// and in this case it uses the new {} list constructor syntax.
mipmap.emplace_back(MipLevel{width, height, pixels});

This comment is misleading. To be constructed in placed, we'd write, mipmap.emplace_back(width, height, pixels). But this isn't possible as MipLevel is an aggregate type. Instead, MipLevel is constructed by the call to MipLevel{...}, which is then passed to MipLevel's implicit move constructor to construct the actual MipLevel element in the vector.

To emphasize that we're not actually constructing the object in place, we should use push_back (and remove the comment):

mipmap.push_back(MipLevel{width, height, pixels});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant