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:
Paul Hollinsky
2021-04-23 20:01:53 -04:00
parent b7ce9819bd
commit 6c1cbc9db8
44 changed files with 1 additions and 5 deletions
@@ -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