Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nullptr.h Source File

nullptr.h

Go to the documentation of this file.
00001 ///\file
00002 
00003 /******************************************************************************
00004 The MIT License(MIT)
00005 
00006 Embedded Template Library.
00007 https://github.com/ETLCPP/etl
00008 http://www.etlcpp.com
00009 
00010 Copyright(c) 2014 jwellbelove
00011 
00012 Permission is hereby granted, free of charge, to any person obtaining a copy
00013 of this software and associated documentation files(the "Software"), to deal
00014 in the Software without restriction, including without limitation the rights
00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00016 copies of the Software, and to permit persons to whom the Software is
00017 furnished to do so, subject to the following conditions :
00018 
00019 The above copyright notice and this permission notice shall be included in all
00020 copies or substantial portions of the Software.
00021 
00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00028 SOFTWARE.
00029 ******************************************************************************/
00030 
00031 #ifndef __ETL_NULLPTR__
00032 #define __ETL_NULLPTR__
00033 
00034 #include "platform.h "
00035 
00036 ///\defgroup nullptr nullptr
00037 /// A definition of nullptr for compilers that don't support it as standard.
00038 ///\ingroup utilities
00039 
00040 #if (ETL_NO_NULLPTR_SUPPORT && !defined(ARDUINO))
00041 namespace std
00042 {
00043   //*****************************************************************************
00044   /// A null pointer type.
00045   ///\ingroup nullptr
00046   //*****************************************************************************
00047   class nullptr_t
00048   {
00049   public:
00050 
00051     // Convertible to any type of null non-member pointer.
00052     template<typename T>
00053     operator T*() const
00054     {
00055       return 0;
00056     }
00057 
00058     // Or any type of null member pointer.
00059     template<typename ANYCLASS, typename T>
00060     operator T ANYCLASS::*() const
00061     {
00062       return 0;
00063     }
00064 
00065   private:
00066 
00067     // Can't take address of nullptr.
00068     void operator&() const;
00069   };
00070 
00071   //*****************************************************************************
00072   /// A null pointer.
00073   ///\ingroup nullptr
00074   //*****************************************************************************
00075   const nullptr_t nullptr = {};
00076 }
00077 
00078 //*****************************************************************************
00079 /// A null pointer.
00080 ///\ingroup nullptr
00081 //*****************************************************************************
00082 const std::nullptr_t nullptr = {};
00083 
00084 #else 
00085     #include <cstddef>
00086 #endif
00087 
00088 #if defined(ARDUINO)
00089 namespace std
00090 {
00091   typedef ::nullptr_t nullptr_t;
00092 }
00093 #endif
00094 
00095 #endif
00096 
00097