-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Use til::some<T,N> to replace the SomeViewports class #4174
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
namespace til | ||
{ | ||
// The at function declares that you've already sufficiently checked that your array access | ||
// is in range before retrieving an item inside it at an offset. | ||
// This is to save double/triple/quadruple testing in circumstances where you are already | ||
// pivoting on the length of a set and now want to pull elements out of it by offset | ||
// without checking again. | ||
// gsl::at will do the check again. As will .at(). And using [] will have a warning in audit. | ||
template<class T> | ||
constexpr auto at(T& cont, const size_t i) -> decltype(cont[cont.size()]) | ||
{ | ||
#pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions | ||
#pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator. | ||
return cont[i]; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler also complains about this throwing exception. But logically this method does not throw anything. And I'm surprised that the
Substract
is not used anywhere. Should I make it non-noexcept
or just catch the exception inside it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so this is an interesting one.
push_back
onsome
can throw an exception if it's full, so technically this one can throw an exception.We know through static analysis (like, with our eyes) that it will never throw...
@miniksa what do you think about cases like this? This will never except until 4 becomes less than 3...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nnnnn. A few ideas all of which I don't really like....
except
: That then pollutes all callers. Yuck.noexcept
that throws technically goes straight tostd::terminate
which is more or less the same as try/CATCH_FAIL_FAST.til::some
. I can't think of one that wouldn't also suffer from this. If you do it with just unchecked array access, now you have a different warning and needtil::at
. If you do it withsome.at()
, that would presumably throw out of bounds too. If we add any other method, then it doesn't look quite like the STL collections it is mocking.I'm leaning toward 2. I hate 1 and 4. I really don't like 3 as it's implicit instead of explicit like 2.
Doing 2 is also generally what we do around the codebase for this problem.
Also, this applies to
.ToOrigin()
below as well, right?