forked from taocpp/sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// The Art of C++ / Sequences | ||
// Copyright (c) 2015 Daniel Frey | ||
|
||
#ifndef TAOCPP_SEQUENCES_INCLUDE_MAX_HPP | ||
#define TAOCPP_SEQUENCES_INCLUDE_MAX_HPP | ||
|
||
#include "fold.hpp" | ||
|
||
#include <type_traits> | ||
|
||
namespace tao | ||
{ | ||
namespace seq | ||
{ | ||
namespace impl | ||
{ | ||
template< typename T, T A, T B > | ||
using max = std::integral_constant< T, ( ( A > B ) ? A : B ) >; | ||
} | ||
|
||
template< typename T, T... Ns > | ||
using max = fold< impl::max, T, Ns... >; | ||
} | ||
} | ||
|
||
#endif // TAOCPP_SEQUENCES_INCLUDE_MAX_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// The Art of C++ / Sequences | ||
// Copyright (c) 2015 Daniel Frey | ||
|
||
#ifndef TAOCPP_SEQUENCES_INCLUDE_MIN_HPP | ||
#define TAOCPP_SEQUENCES_INCLUDE_MIN_HPP | ||
|
||
#include "fold.hpp" | ||
|
||
#include <type_traits> | ||
|
||
namespace tao | ||
{ | ||
namespace seq | ||
{ | ||
namespace impl | ||
{ | ||
template< typename T, T A, T B > | ||
using min = std::integral_constant< T, ( ( A < B ) ? A : B ) >; | ||
} | ||
|
||
template< typename T, T... Ns > | ||
using min = fold< impl::min, T, Ns... >; | ||
} | ||
} | ||
|
||
#endif // TAOCPP_SEQUENCES_INCLUDE_MIN_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// The Art of C++ / Sequences | ||
// Copyright (c) 2015 Daniel Frey | ||
|
||
#include <tao/seq/max.hpp> | ||
|
||
#include <type_traits> | ||
|
||
int main() | ||
{ | ||
using namespace tao::seq; | ||
|
||
static_assert( max< int, 1 >::value == 1, "oops" ); | ||
static_assert( max< int, 1, 0 >::value == 1, "oops" ); | ||
static_assert( max< int, 0, 1 >::value == 1, "oops" ); | ||
static_assert( max< int, 1, -1 >::value == 1, "oops" ); | ||
static_assert( max< int, -1, 1 >::value == 1, "oops" ); | ||
static_assert( max< int, -1, 1, 2 >::value == 2, "oops" ); | ||
static_assert( max< int, -1, 2, 1 >::value == 2, "oops" ); | ||
static_assert( max< int, 2, -1, 1 >::value == 2, "oops" ); | ||
static_assert( max< int, 0, 1, 2, -1, 1, 0, -1, 1 >::value == 2, "oops" ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// The Art of C++ / Sequences | ||
// Copyright (c) 2015 Daniel Frey | ||
|
||
#include <tao/seq/min.hpp> | ||
|
||
#include <type_traits> | ||
|
||
int main() | ||
{ | ||
using namespace tao::seq; | ||
|
||
static_assert( min< int, 1 >::value == 1, "oops" ); | ||
static_assert( min< int, 1, 0 >::value == 0, "oops" ); | ||
static_assert( min< int, 0, 1 >::value == 0, "oops" ); | ||
static_assert( min< int, 1, -1 >::value == -1, "oops" ); | ||
static_assert( min< int, -1, 1 >::value == -1, "oops" ); | ||
static_assert( min< int, -1, 1, 2 >::value == -1, "oops" ); | ||
static_assert( min< int, -1, 2, 1 >::value == -1, "oops" ); | ||
static_assert( min< int, 2, -1, 1 >::value == -1, "oops" ); | ||
static_assert( min< int, 0, 1, 2, -1, 1, 0, -1, 1 >::value == -1, "oops" ); | ||
} |