mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Optional: Move optional-lite to the include/third-party directory
This fixes the use case of adding the include folder manually to an outside project.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include "nonstd/optional.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
using nonstd::optional;
|
||||
using nonstd::nullopt;
|
||||
|
||||
optional<int> to_int( char const * const text )
|
||||
{
|
||||
char * pos = NULL;
|
||||
const int value = static_cast<int>( strtol( text, &pos, 0 ) );
|
||||
|
||||
return pos == text ? nullopt : optional<int>( value );
|
||||
}
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
const char * text = argc > 1 ? argv[1] : "42";
|
||||
|
||||
optional<int> oi = to_int( text );
|
||||
|
||||
if ( oi ) std::cout << "'" << text << "' is " << *oi << std::endl;
|
||||
else std::cout << "'" << text << "' isn't a number" << std::endl;
|
||||
}
|
||||
|
||||
// cl -nologo -W3 -EHsc -I../include to_int.cpp && to_int x1
|
||||
// g++ -Wall -Wextra -std=c++03 -I../include -o to_int.exe to_int.cpp && to_int x1
|
||||
Reference in New Issue
Block a user