importing gsl::span if std::span is not available#1167
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1167 +/- ##
=======================================
Coverage 93.29% 93.29%
=======================================
Files 174 174
Lines 6404 6404
=======================================
Hits 5974 5974
Misses 430 430
|
…lable-and-WITH_GSL-is-on
…lable-and-WITH_GSL-is-on
| # if __has_include(<version>) // Check for __cpp_{feature} | ||
| # include <version> | ||
| # if defined(__cpp_lib_span) | ||
| # if defined(__cpp_lib_span) && __cplusplus > 201703L |
There was a problem hiding this comment.
because __cpp_lib_span is defined for C++17 on g++-10:g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0.
I use these CMake options for build:
-DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_CXX_STANDARD=17
There was a problem hiding this comment.
Which should be ok right? If the HAVE_CPP_STDLIB option is specified, and the standard library provides the implementation ( stable or experimental) it should get selected. What is the behavior now with these changes on g++-10/C++17 - compilation failure as std::span is not available?
There was a problem hiding this comment.
The behavior for g++-10/C++17 is that nostd::span will be picked if the WITH_GSL option was not used. I think we shouldn't use std::span if the user explicitly asks for C++17.
Shall I enable std::span if C++17 was used and std::span is available?
| endif() | ||
|
|
||
| if(WITH_GSL) | ||
| add_definitions(-DHAVE_GSL) |
There was a problem hiding this comment.
Just to clarify- with this PR, GSL library will only be used if the WITH_GSL flag is enabled?
There was a problem hiding this comment.
yes it is enabled only when the user explicitly asks for it.
There was a problem hiding this comment.
Ok, I was thinking about this part in cmake:
opentelemetry-cpp/api/CMakeLists.txt
Lines 48 to 51 in 05d43d6
As it looks we are enabling HAVE_GSL macro with WITH_STL option, which would mean try using gsl::span from submodule if STL doesn't have std::span implementation.
There was a problem hiding this comment.
that is covered in
opentelemetry-cpp/api/include/opentelemetry/std/span.h
Lines 29 to 31 in bc1b469
WITH_GSL is off.We shouldn't define it though, I cleaned it from the CMake file.
There was a problem hiding this comment.
ok, thanks for the clarification.
…lable-and-WITH_GSL-is-on
…lable-and-WITH_GSL-is-on
…lable-and-WITH_GSL-is-on
Fixes #813 (issue)
Changes
If the
WITH_STLcmake option is enabled, the build will usestd::spanif available (for C++20), and fall back tonostd::spaninstead ofgsl::span(or perhaps fail the build). Usesgsl::spanonly if explicitly specified theWITH_GSLbuild option.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes