Comments (4)
The code on cppreference.com is just copied from the corresponding C++ Standard proposal, but the code itself is actually much older than that and has been floating around on the internet for years. I don't even know who the original author is and would just assume that the code is public domain.
BTW, the CC-BY-SA licensing of cppreference.com is only a protection against someone just copying the whole wiki and filling it up with ads to make money from it.
from dbg-macro.
Just to give you some reassurance, libstdc++
has the exact same code in the standard library, just with the variables renamed:
https://github.com/gcc-mirror/gcc/blob/b05c7e439a823d99781e4aaa47a9782fa6693cb5/libstdc%2B%2B-v3/include/std/type_traits#L2582-L2598
https://github.com/gcc-mirror/gcc/blob/b05c7e439a823d99781e4aaa47a9782fa6693cb5/libstdc%2B%2B-v3/include/experimental/type_traits#L228-L250
from dbg-macro.
I recommand is_detected
for that.
#include <type_traits>
// -- begin is_detected
// https://en.cppreference.com/w/cpp/experimental/is_detected
struct nonesuch {
~nonesuch() = delete;
nonesuch(nonesuch const&) = delete;
void operator=(nonesuch const&) = delete;
};
namespace detail {
template <typename ...>
using void_t = void;
template <class Default, class AlwaysVoid,
template<class...> class Op, class... Args>
struct detector {
using value_t = std::false_type;
using type = Default;
};
template <class Default, template<class...> class Op, class... Args>
struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
using value_t = std::true_type;
using type = Op<Args...>;
};
} // namespace detail
template <template<class...> class Op, class... Args>
using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
template <template<class...> class Op, class... Args>
using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type;
template <class Default, template<class...> class Op, class... Args>
using detected_or = detail::detector<Default, void, Op, Args...>;
// -- end is_detected
template <typename T>
using detect_begin_t = decltype(begin(std::declval<T>()));
template <typename T>
using detect_end_t = decltype(end(std::declval<T>()));
template <typename T>
using detect_size_t = decltype(std::declval<T>().size());
template <typename T>
struct has_begin_end_size {
static constexpr bool value = is_detected<detect_begin_t, T>::value
&& is_detected<detect_end_t, T>::value
&& is_detected<detect_size_t, T>::value;
};
template <typename Container>
typename std::enable_if<has_begin_end_size<Container>::value, bool>::type
prettyPrint(std::ostream &stream, Container const &value) {
// ...
}
from dbg-macro.
Thank you very much!
I didn't know is_detected
. That seems like a very useful "wrapper" around std::void_t
.
Ideally, I would like to keep dbg.h
C++11 compatible, so we would have to include an implementation of void_t
as well.
(a technical thing: the content on cppreference.com seems to be CC-BY-SA licensed. I'm not really familiar with the details, but I don't think it's compatible with MIT)
from dbg-macro.
Related Issues (20)
- Windows Supported? HOT 14
- Broken output of containers HOT 6
- How about output "{?}" string for unknown types instead of failing with static assert? HOT 2
- Allow specifying the output stream HOT 9
- Is support it for android ? HOT 2
- Is it possible to allow variadic template expansion? HOT 8
- VS2015:error C2912 HOT 5
- debug print on some condition HOT 3
- use in Qt HOT 1
- Add output level HOT 2
- `Type does not support the << ostream operator` on custom type HOT 10
- multithread support HOT 1
- Support always on colors HOT 2
- Nested dbg(...) expansion as not expected HOT 2
- How to force print the full content, not the one with ellipsis HOT 3
- Support for container adapters HOT 1
- Fails with Eigen matrices HOT 7
- Suggest /usr/local/include instead of /usr/include HOT 3
- Report a compiling error with old GCC version (GCC 4.8.5) HOT 1
- Some enhancement proposals for CMake based usecases 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 dbg-macro.