diff --git a/src/common/BUILD.gn b/src/common/BUILD.gn index 698b26c9ed..b3b7855f93 100644 --- a/src/common/BUILD.gn +++ b/src/common/BUILD.gn @@ -186,6 +186,7 @@ if (is_win || is_linux || is_chromeos || is_mac || is_fuchsia || is_android) { "SwapChainUtils.h", "SystemUtils.cpp", "SystemUtils.h", + "TypeTraits.h", "TypedInteger.h", "UnderlyingType.h", "ityp_array.h", diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 86812af420..ac8e3360f4 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -48,6 +48,7 @@ target_sources(dawn_common PRIVATE "SwapChainUtils.h" "SystemUtils.cpp" "SystemUtils.h" + "TypeTraits.h" "TypedInteger.h" "UnderlyingType.h" "ityp_array.h" diff --git a/src/common/TypeTraits.h b/src/common/TypeTraits.h new file mode 100644 index 0000000000..3348b892f4 --- /dev/null +++ b/src/common/TypeTraits.h @@ -0,0 +1,34 @@ +// Copyright 2020 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COMMON_TYPETRAITS_H_ +#define COMMON_TYPETRAITS_H_ + +#include + +template +struct HasEqualityOperator { + static constexpr const bool value = false; +}; + +template +struct HasEqualityOperator< + LHS, + RHS, + std::enable_if_t< + std::is_same() == std::declval()), bool>::value>> { + static constexpr const bool value = true; +}; + +#endif // COMMON_TYPE_TRAITS_H_ diff --git a/src/dawn_native/SubresourceStorage.h b/src/dawn_native/SubresourceStorage.h index 4ae07fc99c..fb444d74b6 100644 --- a/src/dawn_native/SubresourceStorage.h +++ b/src/dawn_native/SubresourceStorage.h @@ -16,6 +16,7 @@ #define DAWNNATIVE_SUBRESOURCESTORAGE_H_ #include "common/Assert.h" +#include "common/TypeTraits.h" #include "dawn_native/EnumMaskIterator.h" #include "dawn_native/Subresource.h" @@ -105,6 +106,9 @@ namespace dawn_native { template class SubresourceStorage { public: + static_assert(std::is_copy_assignable::value, "T must be copyable"); + static_assert(HasEqualityOperator::value, "T requires bool operator == (T, T)"); + // Creates the storage with the given "dimensions" and all subresources starting with the // initial value. SubresourceStorage(Aspect aspects,