mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
add gsl::index typedef
cppcoreguidelines referece: ES.107: Don't use unsigned for subscripts, prefer gsl::index https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-subscripts
This commit is contained in:
parent
c87c123d1b
commit
2e4213a11a
@ -21,6 +21,7 @@
|
|||||||
#include <gsl/gsl_assert> // Ensures/Expects
|
#include <gsl/gsl_assert> // Ensures/Expects
|
||||||
#include <gsl/gsl_byte> // byte
|
#include <gsl/gsl_byte> // byte
|
||||||
#include <gsl/gsl_util> // finally()/narrow()/narrow_cast()...
|
#include <gsl/gsl_util> // finally()/narrow()/narrow_cast()...
|
||||||
|
#include <gsl/index> // index
|
||||||
#include <gsl/multi_span> // multi_span, strided_span...
|
#include <gsl/multi_span> // multi_span, strided_span...
|
||||||
#include <gsl/pointers> // owner, not_null
|
#include <gsl/pointers> // owner, not_null
|
||||||
#include <gsl/span> // span
|
#include <gsl/span> // span
|
||||||
|
27
include/gsl/index
Normal file
27
include/gsl/index
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
//
|
||||||
|
// This code is licensed under the MIT License (MIT).
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef GSL_INDEX_H
|
||||||
|
#define GSL_INDEX_H
|
||||||
|
|
||||||
|
#include <cstddef> // for ptrdiff_t
|
||||||
|
|
||||||
|
namespace gsl
|
||||||
|
{
|
||||||
|
using index = std::ptrdiff_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GSL_INDEX_H
|
@ -101,3 +101,4 @@ add_gsl_test(utils_tests)
|
|||||||
add_gsl_test(owner_tests)
|
add_gsl_test(owner_tests)
|
||||||
add_gsl_test(byte_tests)
|
add_gsl_test(byte_tests)
|
||||||
add_gsl_test(algorithm_tests)
|
add_gsl_test(algorithm_tests)
|
||||||
|
add_gsl_test(index_test)
|
||||||
|
26
tests/index_test.cpp
Normal file
26
tests/index_test.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
//
|
||||||
|
// This code is licensed under the MIT License (MIT).
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <catch/catch.hpp>
|
||||||
|
#include <type_traits> // for is_same
|
||||||
|
|
||||||
|
#include <gsl/index> // for index
|
||||||
|
|
||||||
|
TEST_CASE("sanity check for gsl::index typedef")
|
||||||
|
{
|
||||||
|
static_assert(std::is_same<gsl::index, std::ptrdiff_t>::value,
|
||||||
|
"gsl::index represents wrong arithmetic type");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user