mirror of
https://github.com/boostorg/lambda2.git
synced 2026-01-20 16:42:16 +00:00
Compare commits
8 Commits
boost-1.77
...
feature/sp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08b40af530 | ||
|
|
d6389b60f5 | ||
|
|
f2ab3ade7c | ||
|
|
e2251ab450 | ||
|
|
3a06c98e8d | ||
|
|
8b08326f6e | ||
|
|
b9cc0aa5d1 | ||
|
|
58c947fcf9 |
45
.github/workflows/ci.yml
vendored
45
.github/workflows/ci.yml
vendored
@@ -17,24 +17,13 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: gcc-4.7
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.7
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.8
|
||||
- toolset: gcc-4.9
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.9
|
||||
- toolset: gcc-5
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "03,11,14,17"
|
||||
@@ -45,7 +34,7 @@ jobs:
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
- toolset: gcc-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
@@ -53,40 +42,20 @@ jobs:
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
install: g++-11
|
||||
- toolset: clang
|
||||
compiler: clang++-3.5
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.5
|
||||
- toolset: clang
|
||||
compiler: clang++-3.6
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.6
|
||||
- toolset: clang
|
||||
compiler: clang++-3.7
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.7
|
||||
- toolset: clang
|
||||
compiler: clang++-3.8
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.8
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
|
||||
@@ -5,15 +5,15 @@ described in [this post](https://pdimov.github.io/blog/2020/07/22/a-c14-lambda-l
|
||||
|
||||
It has no dependencies and consists of a [single header](include/boost/lambda2/lambda2.hpp).
|
||||
|
||||
See [the documentation](https://www.boost.org/doc/libs/develop/libs/lambda2/) for more information.
|
||||
See [the documentation](https://www.boost.org/libs/lambda2/) for more information.
|
||||
|
||||
## Supported Compilers
|
||||
|
||||
* g++ 5 or later with `-std=c++14` or above
|
||||
* clang++ 3.5 or later with `-std=c++14` or above
|
||||
* clang++ 3.9 or later with `-std=c++14` or above
|
||||
* Visual Studio 2015, 2017, 2019
|
||||
|
||||
Tested on [Travis](https://travis-ci.org/github/pdimov/lambda2/) and
|
||||
Tested on [Github Actions](https://github.com/boostorg/lambda2/actions) and
|
||||
[Appveyor](https://ci.appveyor.com/project/pdimov/lambda2).
|
||||
|
||||
## License
|
||||
|
||||
@@ -14,6 +14,7 @@ Peter Dimov
|
||||
:leveloffset: +1
|
||||
|
||||
include::lambda2/overview.adoc[]
|
||||
include::lambda2/changelog.adoc[]
|
||||
include::lambda2/reference.adoc[]
|
||||
include::lambda2/copyright.adoc[]
|
||||
|
||||
|
||||
14
doc/lambda2/changelog.adoc
Normal file
14
doc/lambda2/changelog.adoc
Normal file
@@ -0,0 +1,14 @@
|
||||
////
|
||||
Copyright 2021 Peter Dimov
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#changelog]
|
||||
# Revision History
|
||||
:idprefix:
|
||||
|
||||
## Changes in 1.78.0
|
||||
|
||||
* Added special cases in `operator<<` and `operator>>` when
|
||||
the first argument is a stream, to allow `std::cout << _1`.
|
||||
@@ -66,7 +66,7 @@ None. A single, self-contained header.
|
||||
## Supported Compilers
|
||||
|
||||
* GCC 5 or later with `-std=c++14` or above
|
||||
* Clang 3.5 or later with `-std=c++14` or above
|
||||
* Clang 3.9 or later with `-std=c++14` or above
|
||||
* Visual Studio 2015, 2017, 2019
|
||||
|
||||
Tested on https://github.com/boostorg/lambda2/actions[Github Actions] and
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
#include <cstddef>
|
||||
#include <iosfwd>
|
||||
|
||||
// Same format as BOOST_VERSION:
|
||||
// major * 100000 + minor * 100 + patch
|
||||
#define BOOST_LAMBDA2_VERSION 107700
|
||||
#define BOOST_LAMBDA2_VERSION 107800
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -151,6 +152,8 @@ template<class A> using enable_unary_lambda =
|
||||
template<class A, class B> using enable_binary_lambda =
|
||||
std::enable_if_t<is_lambda_expression<A>::value || is_lambda_expression<B>::value>;
|
||||
|
||||
template<class T> using is_stream = std::is_base_of<std::ios_base, remove_cvref_t<T>>;
|
||||
|
||||
} // namespace lambda2_detail
|
||||
|
||||
#define BOOST_LAMBDA2_UNARY_LAMBDA(op, fn) \
|
||||
@@ -201,9 +204,6 @@ BOOST_LAMBDA2_UNARY_LAMBDA(~, std::bit_not<>)
|
||||
|
||||
// additional
|
||||
|
||||
BOOST_LAMBDA2_BINARY_LAMBDA(<<, lambda2_detail::left_shift)
|
||||
BOOST_LAMBDA2_BINARY_LAMBDA(>>, lambda2_detail::right_shift)
|
||||
|
||||
BOOST_LAMBDA2_UNARY_LAMBDA(+, lambda2_detail::unary_plus)
|
||||
BOOST_LAMBDA2_UNARY_LAMBDA(*, lambda2_detail::dereference)
|
||||
|
||||
@@ -226,6 +226,38 @@ BOOST_LAMBDA2_BINARY_LAMBDA(^=, lambda2_detail::bit_xor_equal)
|
||||
BOOST_LAMBDA2_BINARY_LAMBDA(<<=, lambda2_detail::left_shift_equal)
|
||||
BOOST_LAMBDA2_BINARY_LAMBDA(>>=, lambda2_detail::right_shift_equal)
|
||||
|
||||
// operator<<
|
||||
|
||||
template<class A, class = std::enable_if_t<!lambda2_detail::is_stream<A>::value>,
|
||||
class B, class = lambda2_detail::enable_binary_lambda<A, B>>
|
||||
auto operator<<( A&& a, B&& b )
|
||||
{
|
||||
return std::bind( lambda2_detail::left_shift(), std::forward<A>(a), std::forward<B>(b) ); \
|
||||
}
|
||||
|
||||
template<class A, class = std::enable_if_t<lambda2_detail::is_stream<A>::value>,
|
||||
class B, class = lambda2_detail::enable_unary_lambda<B>>
|
||||
auto operator<<( A& a, B&& b )
|
||||
{
|
||||
return std::bind( lambda2_detail::left_shift(), std::ref(a), std::forward<B>(b) );
|
||||
}
|
||||
|
||||
// operator>>
|
||||
|
||||
template<class A, class = std::enable_if_t<!lambda2_detail::is_stream<A>::value>,
|
||||
class B, class = lambda2_detail::enable_binary_lambda<A, B>>
|
||||
auto operator>>( A&& a, B&& b )
|
||||
{
|
||||
return std::bind( lambda2_detail::right_shift(), std::forward<A>(a), std::forward<B>(b) ); \
|
||||
}
|
||||
|
||||
template<class A, class = std::enable_if_t<lambda2_detail::is_stream<A>::value>,
|
||||
class B, class = lambda2_detail::enable_unary_lambda<B>>
|
||||
auto operator>>( A& a, B&& b )
|
||||
{
|
||||
return std::bind( lambda2_detail::right_shift(), std::ref(a), std::forward<B>(b) );
|
||||
}
|
||||
|
||||
} // namespace lambda2
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -24,3 +24,5 @@ run placeholders.cpp ;
|
||||
run increment.cpp ;
|
||||
run subscript.cpp ;
|
||||
run compound.cpp ;
|
||||
run stream_insert.cpp ;
|
||||
run stream_extract.cpp ;
|
||||
|
||||
42
test/stream_extract.cpp
Normal file
42
test/stream_extract.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/lambda2.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
template<class T> T from_string_1( std::string const& s )
|
||||
{
|
||||
using namespace boost::lambda2;
|
||||
|
||||
std::istringstream is( s );
|
||||
|
||||
T t{};
|
||||
|
||||
( std::ref( is ) >> _1 )( t );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
template<class T> T from_string_2( std::string const& s )
|
||||
{
|
||||
using namespace boost::lambda2;
|
||||
|
||||
std::istringstream is( s );
|
||||
|
||||
T t{};
|
||||
|
||||
( is >> _1 )( t );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_EQ( from_string_1<int>( "123" ), 123 );
|
||||
BOOST_TEST_EQ( from_string_2<int>( "456" ), 456 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
38
test/stream_insert.cpp
Normal file
38
test/stream_insert.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/lambda2.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
template<class T> std::string to_string_1( T const& t )
|
||||
{
|
||||
using namespace boost::lambda2;
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
( std::ref( os ) << _1 )( t );
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template<class T> std::string to_string_2( T const& t )
|
||||
{
|
||||
using namespace boost::lambda2;
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
( os << _1 )( t );
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_EQ( to_string_1( 123 ), "123" );
|
||||
BOOST_TEST_EQ( to_string_2( 456 ), "456" );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user