Comments (2)
is_true and is_false work nice, but I find myself doing n-ary std::integral_constant<bool, A::value || B::value || ...>
There is is_true_c
and is_false_c
that take a boolean directly, so you don't have to wrap it in an integral constant. So you should just be able to write is_true_c<(A() || B() || ...)>
directly.
The usual n-ary or_ metafunction should do the trick.
I would prefer not to add that to this library, since this is a traits library and not a metaprogramming library. I believe Eric Niebler's meta library has an or_
metafunction.
In many cases, a concept requirement is not a set of mandatory properties in a way that all of them should be accomplished by the type, but a set of possible properties.
Usually when you need an or
of the type requirements is when overloading is involved. However, you can just check if the expression is valid instead. For example, a generic print
that works for any streamable type as well as for tuples and ranges could be written like this using the Fit library:
FIT_STATIC_FUNCTION(print) = fit::conditional(
[](const auto& x) -> decltype(std::cout << x, void())
{
std::cout << x << std::endl;
},
[](const auto& range) -> decltype(std::cout << *adl::adl_begin(range), void())
{
for(const auto& x:range) std::cout << x << std::endl;
},
[](const auto& tuple) -> decltype(for_each_tuple(tuple, fit::identity), void())
{
return for_each_tuple(tuple, [](const auto& x)
{
std::cout << x << std::endl;
});
}
);
Rather than check with or
that it meets the requirements of each overload, I can instead just check if print
is a valid expression:
TICK_TRAIT(is_printable)
{
template<class T>
auto require(const T& x) -> decltype(print(x));
};
from tick.
Just as a note for anyone else browsing this: C++17 has std::disjunction for logical or on type traits. You can easily replicate it if your compiler doesn't have C++17 support, see: http://en.cppreference.com/w/cpp/types/disjunction
Also, would be nice if is_true_c and is_false_c would be mentioned in the documentation: I had a really hard time finding them...
from tick.
Related Issues (11)
- how does one check to see whether a trait is true or false? HOT 12
- `require` with non-template arguments breaks HOT 2
- Can I require that an expression be noexcept? HOT 2
- Any license? HOT 2
- TICK_REQUIRES with parameter pack template
- How to Declare Tick class as friend
- Boost propsal status?
- How to disable C<T>.f(T) for T void? HOT 2
- concept primitives? HOT 13
- Use variable templates to avoid unwanted parse? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tick.