1/*******************************************************************************
2* Copyright 2021 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef COMMON_CPP_COMPAT_HPP
18#define COMMON_CPP_COMPAT_HPP
19
20#include <exception>
21#include <type_traits>
22
23namespace dnnl {
24namespace impl {
25namespace cpp_compat {
26
27// oneDNN relies on C++11 standard. However, for DPCPP runtime the standard we
28// use to build oneDNN must be C++17 per requirements. Some C++11 features have
29// been deprecated in C++17, which triggers deprecations warnings. This file
30// contains a compatibility layer for such C++ features.
31
32// Older than C++17.
33#if defined(__cplusplus) && __cplusplus < 201703L
34inline int uncaught_exceptions() {
35 return (int)std::uncaught_exception();
36}
37
38template <class F, class... ArgTypes>
39using invoke_result = std::result_of<F(ArgTypes...)>;
40#else
41
42inline int uncaught_exceptions() {
43 return std::uncaught_exceptions();
44}
45
46template <class F, class... ArgTypes>
47using invoke_result = std::invoke_result<F, ArgTypes...>;
48
49#endif
50} // namespace cpp_compat
51} // namespace impl
52} // namespace dnnl
53
54#endif
55