How to use c++ thingie called “Span”

Bryan Kelly 486 Reputation points
2022-10-29T02:44:04.447+00:00

Windows 11, Visual Studio 2019, C++, Base58 encoder
I am trying to incorporate functions to do Base58 encoding and decoding. They are widely used by Bitcoin.
The code I am trying is here: https://github.com/bitcoin/bitcoin/blob/master/src/base58.cpp
I have added several includes and down to one error in three places. Example:

std::string EncodeBase58(Span<const unsigned char> input)  

I have gone through several variations to include std::span and gsl::span and none are accepted. I “think” I can remove it by replacing the argument with the specified array plus a size_t argument for the size. But, I would like to keep it as is.
What is the right configuration for VS 2019 C++?

PS: The tool to add a hyperlink uses http:// Maybe update it to https://

Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,551 Reputation points
    2022-10-29T21:46:49.603+00:00

    Did you remember to set /std:c++20 for all platform/configuration conbinations? If you did not it's possible that what you see for your project is because the platform/configuration that you're looking at doesn't have the proper setting.

    1 person found this answer helpful.
    0 comments No comments

8 additional answers

Sort by: Most helpful
  1. RLWA32 49,551 Reputation points
    2022-10-29T20:12:05.663+00:00

    C++ is case sensitive. Use span, not Span.

    1 person found this answer helpful.
    0 comments No comments

  2. Marius H 1 Reputation point
    2022-10-29T03:21:24.58+00:00

    They use their own implementation located at bitcoin/blob/master/src/span.h.

    0 comments No comments

  3. Bryan Kelly 486 Reputation points
    2022-10-29T03:51:30.58+00:00

    Well now.
    I read that using span reduces argument from something like:

    function( &array, size )
    to
    function( span<type> input );

    But after seeing all that code, I wonder if it is really worth that much effort.
    Some advantages are described in some web pages, but I lack the experience to understand the significant improvement.

    Thank you for the info.

    0 comments No comments

  4. Bryan Kelly 486 Reputation points
    2022-10-29T19:49:17.757+00:00

    I am running VS 2019 version 16.11.20.
    from this page: msvcs-stl-completes-stdc20

    and this quote:

    We previously announced that MSVC had completed all features in C++20 for Visual Studio version 16.11.0, and that we had added the /std:c++20 option to indicate that most C++20 features were stabilized and considered production-ready.

    And from a few searches it seems that the "span" feature is part of C++20. But my VS is not recognizing the key word span. Below are a few lines from a dot h file.

    What steps are needed to recognize this feature?

    255269-span-not-recognized.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.