Skip to content

Move to GSL 3.1.0 - #6908

Merged
1 commit merged into
masterfrom
dev/duhowett/gsl3
Jul 14, 2020
Merged

1 commit merged into
masterfrom
dev/duhowett/gsl3

Conversation

@DHowett

@DHowett Dustin L. Howett (DHowett) commented Jul 14, 2020 •

Copy link
Copy Markdown
Member

GSL 3, the next major version of GSL after the one we're using, replaced
their local implementation of span with one that more closely mimics
C++20's span. Unfortunately, that is a breaking change for all of GSL's
consumers.

This commit updates our use of span to comply with the new changes in
GSL 3.

Chief among those breaking changes is:

  • span::at no longer exists; I replaced many instances of span::at
    with gsl::at(x)
  • span::size_type has finally given up on ptrdiff_t and become
    size_t like all other containers

While I was here, I also made the following mechanical replacements:

  • In some of our "early standardized" code, we used std::optional's
    has_value and value back-to-back. Each value incurs an
    additional presence test.
    • Change: x.value().member -> x->member (optional::operator->
      skips the presence test)
    • Change: x.value() -> *x (as above)
  • GSL 3 uses size_t for size_type.
    • Change: gsl::narrow<size_t>(x.size()) -> x.size()
    • Change: gsl::narrow<ptrdiff_t>(nonSpan.size()) -> nonSpan.size()
      during span construction

I also replaced two instances of x[x.size() - 1] with x.back() and
one instance of a manual array walk (for comparison) with a direct
comparison.

NOTE: Span comparison and make_span are not part of the C++20 span
library.

Fixes #6251

@ghost ghost added Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Conhost For issues in the Console codebase Product-Terminal The new Windows Terminal. labels Jul 14, 2020
Comment thread src/types/utils.cpp
table[13] = RGB(180, 0, 158);
table[14] = RGB(97, 214, 214);
table[15] = RGB(242, 242, 242);
gsl::at(table, 0) = RGB(12, 12, 12);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly, this should be an std::copy from a hardcoded table, lol

Comment thread src/inc/LibraryIncludes.h Resolved
GSL 3, the next major version of GSL after the one we're using, replaced
their local implementation of `span` with one that more closely mimics
C++20's span. Unfortunately, that is a breaking change for all of GSL's
consumers.

This commit updates our use of span to comply with the new changes in
GSL 3.

Chief among those breaking changes is:

* `span::at` no longer exists; I replaced many instances of `span::at`
  with `gsl::at(x)`
* `span::size_type` has finally given up on `ptrdiff_t` and become
  `size_t` like all other containers

While I was here, I also made the following mechanical replacements:

* In some of our "early standardized" code, we used std::optional's
  `has_value` and `value` back-to-back. Each `value` incurs an
  additional presence test.
  * Change: `x.value().member` -> `x->member` (`optional::operator->`
    skips the presence test)
* GSL 3 uses `size_t` for `size_type`.
  * Change: `gsl::narrow<size_t>(x.size())` -> `x.size()`
  * Change: `gsl::narrow<ptrdiff_t>(nonSpan.size())` -> `nonSpan.size()`
    during span construction

I also replaced two instances of `x[x.size() - 1]` with `x.back()` and
one instance of a manual array walk (for comparison) with a direct
comparison.

NOTE: Span comparison and `make_span` are not part of the C++20 span
library.

Fixes #6251
@DHowett Dustin L. Howett (DHowett) added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 14, 2020
@ghost

Copy link
Copy Markdown

Hello Dustin L. Howett (@DHowett)!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
ghost merged commit 54a7fce into master Jul 14, 2020
@ghost
ghost deleted the dev/duhowett/gsl3 branch July 14, 2020 18:31
Dustin L. Howett (DHowett) added a commit that referenced this pull request Aug 5, 2020
- Move to GSL 3.1.0 (GH-6908)
- Replace the color table init code with two const arrays (GH-6913)
- Replace basic_string_view<T> with span<const T> (GH-6921)
- Replace gsl::at with a new til::at(span) for pre-checked bounds (GH-6925)

Related work items: MSFT:27866336
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Conhost For issues in the Console codebase Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Become C++20-compliant in our use of span

3 participants