Make the Min/Max initializer_list overloads instantiable - #552
Open
karpovantonme wants to merge 1 commit into
Open
Make the Min/Max initializer_list overloads instantiable#552karpovantonme wants to merge 1 commit into
karpovantonme wants to merge 1 commit into
Conversation
std::initializer_list<const T&> is ill-formed, so any call to these two failed to compile. Take std::initializer_list<T> and return by value, since the backing array of a braced list dies at the end of the full expression. Also add the missing parentheses on lst.size(). Reported in devosoft#550.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #550.
std::initializer_list<const T &>is ill-formed, so the two list overloads ofemp::Minandemp::Maxcould never be instantiated. Any call to them failed inside<initializer_list>itself:with
emp::Min({3, 1, 2})as the whole test case.The overloads now take
std::initializer_list<T>and return by value. Returning a reference would dangle: the backing array of a braced list ends its lifetime at the end of the full expression that contains it, so aconst T &into it is already gone by the time the caller reads it.lst.sizealso gained the parentheses it was missing. As written it took the address of the member function, which is never null, so the assert could not fire.Checked with
c++ -std=c++20 -I include -fsyntax-onlyon a file calling both: it fails on master and compiles here.