cmake/Source/Checks/cm_cxx17_check.cpp

45 lines
934 B
C++
Raw Normal View History

2015-08-17 11:37:30 +02:00
#include <cstdio>
2019-11-11 23:01:05 +01:00
#include <iterator>
2018-10-28 12:09:07 +01:00
#include <memory>
2020-02-01 23:06:01 +01:00
#include <optional>
2018-04-23 21:13:27 +02:00
#include <unordered_map>
2019-11-11 23:01:05 +01:00
#ifdef _MSC_VER
# include <comdef.h>
#endif
2020-08-30 11:54:41 +02:00
template <typename T,
typename std::invoke_result<decltype(&T::get), T>::type = nullptr>
typename T::pointer get_ptr(T& item)
{
return item.get();
}
2016-07-09 11:21:54 +02:00
int main()
{
2019-11-11 23:01:05 +01:00
int a[] = { 0, 1, 2 };
auto ai = std::cbegin(a);
int b[] = { 2, 1, 0 };
auto bi = std::cend(b);
auto ci = std::size(a);
2018-10-28 12:09:07 +01:00
std::unique_ptr<int> u(new int(0));
2019-11-11 23:01:05 +01:00
2020-08-30 11:54:41 +02:00
// Intel compiler do not handle correctly 'decltype' inside 'invoke_result'
get_ptr(u);
2019-11-11 23:01:05 +01:00
#ifdef _MSC_VER
// clang-cl has problems instantiating this constructor in C++17 mode
// error: indirection requires pointer operand ('const _GUID' invalid)
// return *_IID;
IUnknownPtr ptr{};
IDispatchPtr disp(ptr);
#endif
2020-02-01 23:06:01 +01:00
std::optional<int> oi = 0;
return *u + *ai + *(bi - 1) + (3 - static_cast<int>(ci)) + oi.value();
2016-07-09 11:21:54 +02:00
}