Skip to content

Commit

Permalink
Add configuration nsel_CONFIG_WIN32_LEAN_AND_MEAN (proposed in #69, t…
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmoene committed Aug 5, 2024
1 parent 5d3c8d3 commit 884e1f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ At default, *expected lite* uses `std::expected` if it is available and lets you
Define this to `nsel_EXPECTED_STD` to select `std::expected` as `nonstd::expected`. Define this to `nsel_EXPECTED_NONSTD` to select `nonstd::expected` as `nonstd::expected`. Default is undefined, which has the same effect as defining to `nsel_EXPECTED_DEFAULT`.
-D<b>nsel\_P0323R</b>=7 *(default)*
Define this to the proposal revision number to control the presence and behavior of features (see tables). Default is 7 for the latest revision.
Define this to the proposal revision number to control the presence and behavior of features (see tables). Default is 7 for the latest revision.
#### Define `WIN32_LEAN_AND_MEAN`
-D<b>nsel\_CONFIG\_WIN32\_LEAN\_AND\_MEAN</b>=1
Define this to 0 if you want to omit automatic definition of `WIN32_LEAN_AND_MEAN`. Default is 1 when `_MSC_VER` is present.
#### Disable C++ exceptions
Expand Down
12 changes: 12 additions & 0 deletions include/nonstd/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
# define nsel_P2505R 5
#endif

// Lean and mean inclusion of Windows.h, if applicable; default on for MSVC:

#if !defined(nsel_CONFIG_WIN32_LEAN_AND_MEAN) && defined(_MSC_VER)
# define nsel_CONFIG_WIN32_LEAN_AND_MEAN 1
#endif

// Control presence of C++ exception handling (try and auto discover):

#ifndef nsel_CONFIG_NO_EXCEPTIONS
Expand Down Expand Up @@ -277,6 +283,12 @@ namespace nonstd {

// additional includes:

#if nsel_CONFIG_WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
#endif

#if nsel_CONFIG_NO_EXCEPTIONS
# if nsel_CONFIG_NO_EXCEPTIONS_SEH
# include <windows.h> // for ExceptionCodes
Expand Down
13 changes: 12 additions & 1 deletion test/expected-main.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define expected_PRESENT( x ) \
std::cout << #x << ": " << x << "\n"

#define expected_DEFINED( x ) \
std::cout << #x << ": (defined)\n"

#define expected_ABSENT( x ) \
std::cout << #x << ": (undefined)\n"

Expand All @@ -35,15 +38,17 @@ CASE( "expected-lite version" "[.expected][.version]" )
expected_PRESENT( expected_lite_VERSION );
}

CASE( "any configuration" "[.expected][.config]" )
CASE( "expected-lite configuration" "[.expected][.config]" )
{
expected_PRESENT( nsel_HAVE_STD_EXPECTED );
expected_PRESENT( nsel_USES_STD_EXPECTED );
expected_PRESENT( nsel_EXPECTED_DEFAULT );
expected_PRESENT( nsel_EXPECTED_NONSTD );
expected_PRESENT( nsel_EXPECTED_STD );
expected_PRESENT( nsel_CONFIG_SELECT_EXPECTED );
expected_PRESENT( nsel_CONFIG_WIN32_LEAN_AND_MEAN );
expected_PRESENT( nsel_CONFIG_NO_EXCEPTIONS );
expected_PRESENT( nsel_CONFIG_NO_EXCEPTIONS_SEH );
expected_PRESENT( nsel_CPLUSPLUS );
}

Expand Down Expand Up @@ -84,6 +89,12 @@ CASE( "presence of C++ library features" "[.stdlibrary]" )
std::cout << "(Presence of C++ library features not available: using std::expected)\n";
#else

#ifdef WIN32_LEAN_AND_MEAN
expected_DEFINED( WIN32_LEAN_AND_MEAN );
#else
expected_ABSENT( WIN32_LEAN_AND_MEAN );
#endif

#ifdef __cpp_exceptions
expected_PRESENT( __cpp_exceptions );
#else
Expand Down

0 comments on commit 884e1f5

Please sign in to comment.