The following dummy program compiles and runs
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <functional>
#include <utility>
#include <vector>
using boost::adaptors::filtered;
using boost::adaptors::transformed;
auto whatever = [](auto&& x){ return std::forward<decltype(x)>(x); };
auto whenever = [](auto&){ return true; };
int main() {
std::vector<int> v{1,2,3};
auto w1 = v | transformed(whatever);
auto w2 = v | transformed(whatever) | filtered(whenever);
w1.size();
//w2.size();
}
uncommenting the commented line and attempting a compilation with g++ -std=c++14 that_file.cpp
causes this error:
uffa.cpp: In function ‘int main()’:
uffa.cpp:17:8: error: ‘struct
boost::range_detail::filtered_range<<lambda(auto:2&)>, const
boost::range_detail::transformed_range<<lambda(auto:1&&)>, std::vector<int> >
>’ has no member named ‘size’
17 | w2.size();
| ^~~~
Since filtered
, just like transformed
, takes a range and returns a range, I don't understand why size
is not available on filtered
's output.
I know that transformed
and filtered
are two different mathematical functions (e.g. the former assumes that its input is a functor, whereas the latter assumes, correct me if I'm wrong, that its input is a monad), but still... here the input is a std::vector
so what's wrong with asking the size
of the output of filtered
?
question from:
https://stackoverflow.com/questions/65617373/why-output-of-boostadaptorsfiltered-has-no-member-named-size 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…