boost-ext / mp Goto Github PK
View Code? Open in Web Editor NEWC++20 ~~Template~~ Meta-Programming library
C++20 ~~Template~~ Meta-Programming library
C++20 was specified and tried with both GCC11.3 and 12.3, but the same error occurs.
Maybe I'm doing something wrong, please let me know.
root@monica003:/home/monica/test/build# cmake --build .
[ 50%] Building CXX object CMakeFiles/main.dir/test.cpp.o
In file included from /home/monica/test/test.cpp:3:
/home/monica/mp/installed/x64-linux/include/mp-0.0.1/boost/mp.hpp:208:7: error: expected identifier before ‘typeof’
208 | using typeof = decltype(expr(std::declval<Ts>()...));
| ^~~~~~
/home/monica/mp/installed/x64-linux/include/mp-0.0.1/boost/mp.hpp:208:14: error: expected primary-expression before ‘=’ token
208 | using typeof = decltype(expr(std::declval<Ts>()...));
| ^
/home/monica/mp/installed/x64-linux/include/mp-0.0.1/boost/mp.hpp:208:14: error: expected unqualified-id before ‘=’ token
gmake[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/test.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
microsoft/vcpkg#29975 (comment)
root@monica003:/home/monica/test/build# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
Lines 603 to 679 in 73cc053
Unfortunately, this only works currently with clang because of a bug. It's not supposed to (according to http://eel.is/c++draft/temp#deduct.general-9.sentence-1, particularly the Note below that)
great library, I found what I think is a little bug in the readme:
In the first godbolt link in the readme, this example compiles:
static_assert(mp::list<val const>() ==
hello_world(mp::list<int, foo, val, bar>(), add_const, has_value)
);
However, in the readme itself, the example is written without the mp::list::operator()
, which doesn't compile:
static_assert(mp::list<val const> ==
hello_world(mp::list<int, foo, val, bar>, add_const, has_value)
);
()
operators after mp::list<...>
to match the example as it is written in the readmesame as in the original godbolt link
I think the solution is to add the ()
operators in the readme, too.
Is it possible to filter and reorder a parameter pack?
void foo(auto&&... args)
{
qoo(std::forward_as_tuple(std::forward<decltype(args)>(args)...)
| std::views::filter(???)
| std::views::reverse);
}
Currently boost::mp::list is not usable in range based for.
So this is not compiles:
for (char c : mp::list<__PRETTY_FUNCTION__>()) {
std::cout << c;
}
This can be enabled on types where the template arguments are the same.
Possible implementation
#include <https://raw.githubusercontent.com/boost-ext/mp/main/include/boost/mp.hpp>
namespace boost::mp {
template<auto...As>
constexpr static inline auto list_array = std::array{As...};
template<class ...>
constexpr bool is_same_all_v = true;
template<class Ref, class...Oth>
constexpr bool is_same_all_v<Ref, Oth...> = (std::is_same_v<Ref, Oth> && ...);
template<template <auto...> class A, auto...As>
requires is_same_all_v<decltype(As)...>
auto begin(const A<As...>& v) {
return std::begin(list_array<As...>);
}
template<template <auto...> class A, auto...As>
requires is_same_all_v<decltype(As)...>
auto end(const A<As...>& v) {
return std::end(list_array<As...>);
}
} // boost::mp
>------ Build All started: Project: CMakeFindUsage, Configuration: x64-Release ------
MSBuild version 17.4.1+9a89d02ff for .NET Framework
Checking Build System
Building Custom Rule C:/Users/monica/source/repos/CMakeFindUsage/CMakeFindUsage/CMakeLists.txt
CMakeFindUsage.cpp
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(171,13): error C3527: 'Cs' is not a valid operand for 'sizeof...'. Did you mean to use 'sizeof'?
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(569,24): error C3861: '__PRETTY_FUNCTION__': identifier not found
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(569,24): error C2065: '__PRETTY_FUNCTION__': undeclared identifier
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(590,8): error C2065: '__PRETTY_FUNCTION__': undeclared identifier
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(590,8): error C3861: '__PRETTY_FUNCTION__': identifier not found
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(591,14): error C2065: '__PRETTY_FUNCTION__': undeclared identifier
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(591,14): error C3861: '__PRETTY_FUNCTION__': identifier not found
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(597,8): error C2065: '__PRETTY_FUNCTION__': undeclared identifier
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(597,8): error C3861: '__PRETTY_FUNCTION__': identifier not found
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(598,14): error C2065: '__PRETTY_FUNCTION__': undeclared identifier
E:\boost-ext-mp\installed\x64-windows\include\mp-0.0.1\boost\mp.hpp(598,14): error C3861: '__PRETTY_FUNCTION__': identifier not found
Build All failed.
For details, please se: microsoft/vcpkg#29975 (comment).
This is so cool! A few random comments (or questions on what I'm missing if I'm wrong about these things):
Line 283 in 73cc053
I think this should be and
here?
Line 285 in 73cc053
This (and several places above) can just use CTAD, right? [Answering my own question: you can't do CTAD because of the sizeof...(Ts) == 0
case 🤦🏼♀️]
Lines 98 to 106 in 73cc053
Probably not relevant, but this implies that types like int
and float*
are callable
Lines 124 to 125 in 73cc053
Unsolicited suggestion: while you're at it, I like using operator+
for concatenation (so that things like join<TLs...>
can just be implemented as decltype(TLs{} + ... + type_list<>{})
). Maybe not relevant here, but fun thought for later. Here's where I do this in my toy library cutempl
: https://github.com/dhollman/cutempl/blob/5bb6cae4423f0456c21e50454bcba210a94226b3/include/cutempl/containers/type_list.hpp#L14-L21
Lines 389 to 393 in 73cc053
I believe expr_fn
doesn't need to be captured here since it's constexpr
? (In fact, I think it's technically incorrect to do so, but the compiler is just okay with it?)
Also, shouldn't declval
be a non-ADL call here since it could be ambiguous with std::declval
if T
is in std
?
Lines 443 to 444 in 73cc053
Seems like this one could just delegate to the previous overload? Something like value_list<Vs...> | fn | []<auto... Vvs> { return declval<T<R, Vvs...>>() };
(Obviously omitting some corner cases).
Lines 486 to 488 in 73cc053
Seems like requires requires { []<class... Ts>(std::tuple<Ts...>){}(t()); }
would be a more descriptive/self-documenting constraint here.
Lines 714 to 715 in 73cc053
This deduction guide should be unnecessary in C++20 and later
Line 706 in 73cc053
Is there a reason to do this instead of using the comma operator? (Here and elsewhere; Also, if you do use the comma operator, you should do ((void)expr(Ts), ...)
to work around overloaded comma operators)
Lines 80 to 83 in 73cc053
Really nit-picky, but you should ignore digit separators in this loop.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.