Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers static_assert.h Source File

static_assert.h

00001 /******************************************************************************
00002 The MIT License(MIT)
00003 
00004 Embedded Template Library.
00005 https://github.com/ETLCPP/etl
00006 http://www.etlcpp.com
00007 
00008 Copyright(c) 2014 jwellbelove
00009 
00010 Permission is hereby granted, free of charge, to any person obtaining a copy
00011 of this software and associated documentation files(the "Software"), to deal
00012 in the Software without restriction, including without limitation the rights
00013 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00014 copies of the Software, and to permit persons to whom the Software is
00015 furnished to do so, subject to the following conditions :
00016 
00017 The above copyright notice and this permission notice shall be included in all
00018 copies or substantial portions of the Software.
00019 
00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00026 SOFTWARE.
00027 ******************************************************************************/
00028 
00029 #ifndef __ETL_STATIC_ASSERT__
00030 #define __ETL_STATIC_ASSERT__
00031 
00032 #include "platform.h "
00033 
00034 #if (ETL_CPP11_SUPPORTED)
00035   #define STATIC_ASSERT(Condition, Message) static_assert(Condition, Message)
00036 #else
00037   template <bool Condition>
00038   struct STATIC_ASSERT_FAILED;
00039 
00040   template <>
00041   struct STATIC_ASSERT_FAILED<true> {};
00042 
00043   #define ETL_SA1(a,b) a##b
00044   #define ETL_SA2(a,b) ETL_SA1(a,b)
00045   #define STATIC_ASSERT(Condition, Message) \
00046           enum \
00047           { \
00048         ETL_SA2(dummy, __LINE__) = sizeof(STATIC_ASSERT_FAILED<(bool)(Condition)>) \
00049         }
00050 #endif
00051 
00052 #endif
00053