Skip to content

Commit 7142ed6

Browse files
committed
Use gsl::span for argument pointer array
1 parent 6d2b424 commit 7142ed6

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ make -j`nproc`
2424

2525
## Unixservice class
2626
- Main function to run as a unix daemon.
27+
28+
## Dependencies
29+
Because no major compiler supports `std::span` yet the [Microsoft Guidelines Support Library](https://github.com/Microsoft/GSL) (aka GSL) is used for its span implementation (from which the standard version was defined).

cmake/clang_warnings.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ set(WARNING_FLAGS
3939
-Wno-c++98-compat # C++11
4040
-Wno-c++98-compat-pedantic # C++11
4141
-Wno-padded
42+
43+
# brew install microsoft gsl
44+
-Wno-poison-system-directories
4245
)

cmake/find_package.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
#
30+
31+
find_package(Microsoft.GSL CONFIG)

examples/pipe/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ project(pipe)
3333
add_executable(${PROJECT_NAME}
3434
main.cpp
3535
)
36+
37+
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft.GSL::GSL)

examples/pipe/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@
3232
#include <iostream>
3333
#include <vector>
3434

35+
/* gsl header */
36+
#include <gsl/gsl>
37+
#include <gsl/span>
38+
3539
int main( int argc, char **argv ) {
3640

41+
gsl::span<char *> args = { argv, static_cast<std::size_t>( argc ) };
42+
3743
/* Usage: pipe RESULTCODE */
38-
if ( argc != 2 ) {
44+
if ( args.size() != 2 ) {
3945

4046
return EXIT_FAILURE;
4147
}
@@ -46,5 +52,5 @@ int main( int argc, char **argv ) {
4652
fprintf( stderr, "This is fprintf( stderr ) text.\n" );
4753
printf( "This is printf text.\n" );
4854

49-
return std::stoi( argv[ 1 ] );
55+
return std::stoi( gsl::at( args, 1 ) );
5056
}

0 commit comments

Comments
 (0)