Skip to content

Commit

Permalink
New
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Oct 14, 2015
1 parent 35f5097 commit 3d2f600
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/tao/seq/max.hpp
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
26 changes: 26 additions & 0 deletions include/tao/seq/min.hpp
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
21 changes: 21 additions & 0 deletions src/test/seq/max.cpp
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" );
}
21 changes: 21 additions & 0 deletions src/test/seq/min.cpp
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" );
}

0 comments on commit 3d2f600

Please sign in to comment.