/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. #ifndef CRYINCLUDE_CRYCOMMON_COMPILETIMEUTILS_H #define CRYINCLUDE_CRYCOMMON_COMPILETIMEUTILS_H #pragma once #include "MetaUtils.h" // static assert #define STATIC_ASSERT(condition, errMessage) static_assert(condition, errMessage) // static_max template struct static_max { enum { value = (left > right ? left : right), }; }; // static_min template struct static_min { enum { value = (left < right ? left : right), }; }; // static_log2 template struct static_log2 { enum { value = static_log2<(num >> 1)>::value + 1, }; }; template<> struct static_log2<1> { enum { value = 0, }; }; template<> struct static_log2<0> { }; // aligment_type - returns POD type with the desired alignment template struct alignment_type { private: template struct SameAlignment { enum { value = Alignment == alignof(AlignmentType), }; }; public: typedef int (alignment_type::* mptr); typedef int (alignment_type::* mfptr)(); typedef typename metautils::select::value, char, typename metautils::select::value, short, typename metautils::select::value, int, typename metautils::select::value, long, typename metautils::select::value, long long, typename metautils::select::value, float, typename metautils::select::value, double, typename metautils::select::value, long double, typename metautils::select::value, void*, typename metautils::select::value, mptr, typename metautils::select::value, mfptr, char>::type >::type >::type >::type >::type >::type >::type >::type >::type >::type >::type type; }; // aligned_buffer - declares a buffer with desired alignment and size template struct aligned_buffer { private: struct storage { union { typename alignment_type::type _alignment; char _buffer[Size]; } buffer; }; storage buffer; }; // aligned_storage - declares a buffer that can naturally hold the passed type template struct aligned_storage { private: struct storage { union { typename alignment_type::type _alignment; char _buffer[sizeof(Ty)]; } buffer; }; storage buffer; }; // test type equality template struct SSameType { enum { value = false }; }; template struct SSameType { enum { value = true }; }; #endif // CRYINCLUDE_CRYCOMMON_COMPILETIMEUTILS_H