Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2023-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <span.h>7#include <boost/test/unit_test.hpp>8#include <array>9#include <set>10#include <vector>12namespace spannable {13struct Ignore14{15template<typename T> Ignore(T&&) {}16};17template<typename T>18bool Spannable(T&& value, decltype(std::span{value})* enable = nullptr)19{20return true;21}22bool Spannable(Ignore)23{24return false;25}27struct SpannableYes28{29int* data();30int* begin();31int* end();32size_t size();33};34struct SpannableNo35{36void data();37size_t size();38};39} // namespace spannable41using namespace spannable;43BOOST_AUTO_TEST_SUITE(span_tests)45// Make sure template std::span template deduction guides accurately enable calls to46// std::span constructor overloads that work, and disable calls to constructor overloads that47// don't work. This makes it possible to use the std::span constructor in a SFINAE48// contexts like in the Spannable function above to detect whether types are or49// aren't compatible with std::span at compile time.50BOOST_AUTO_TEST_CASE(span_constructor_sfinae)51{52BOOST_CHECK(Spannable(std::vector<int>{}));53BOOST_CHECK(!Spannable(std::set<int>{}));54BOOST_CHECK(!Spannable(std::vector<bool>{}));55BOOST_CHECK(Spannable(std::array<int, 3>{}));56BOOST_CHECK(Spannable(std::span<int>{}));57BOOST_CHECK(Spannable("char array"));58BOOST_CHECK(Spannable(SpannableYes{}));59BOOST_CHECK(!Spannable(SpannableNo{}));60}62BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.