Unustasid parooli?



     
Sisseloginud kasutajatele märgistatakse automaatselt teksti piirkonnad, mis on muutunud alates viimasest lugemisest. Lisandunud osa on roheline, eemaldatud osa punane.
Lisaks märgistatakse sisseloginud kasutajatele menüüs täiendavate värvide abil artiklid, mis on kasutajal loetud (hall), ning artiklid, mis on peale lugemist täienenud (roheline).

   

     

Pealkiri :
Id (lühend aadressiribale) :
Autor ja viimase muudatuse autor :
Loomise aeg ja viimane muudatus :
Teksti pikkus :
Luba ligipääs ainult kasutajanimedele (eralda komadega). Autoril on alati ligipääs. :




C++ compile-time numeric messages
 
Boost has preprocessor macro named BOOST_PP_ASSERT_MSG:
But this only works for string constants. What if You need to debug Your C++ compile-time metaprogram and want to output some numbers unknown at the time of writing the code?
 
Here is the snippet.
 
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>
 
#define FILE_AND_LINE_MESSAGE     MESSAGE(__FILE__ " : " BOOST_PP_STRINGIZE(__LINE__) " :")
 
#define PP_DEC0(v)      BOOST_PP_IF(v, BOOST_PP_DEC(v), -1)   //allows decrementing from the value 0 too
 
#if defined(_MSC_VER) && (_MSC_VER >= 1400)

    #define MESSAGE2(x) __pragma (message(BOOST_PP_STRINGIZE(x)))
    #define MESSAGE(x)  __pragma (message(x)) 

#else
 
    #include <boost/preprocessor/debug/assert.hpp>
 
    #define MESSAGE2(x) BOOST_PP_ASSERT_MSG(1, BOOST_PP_STRINGIZE(x))
    #define MESSAGE(x)  BOOST_PP_ASSERT_MSG(1, x)     
  
#endif
 
#ifdef __cplusplus
 
    template <int val, int dummyI>
    struct numeric_message;  
 
    #define DEFINE_NUMERIC_MESSAGE_T(z, n, data)   template <int dummyI> struct numeric_message<n - 1, dummyI> { numeric_message() { MESSAGE(BOOST_PP_STRINGIZE(BOOST_PP_CAT(val :, PP_DEC0(n)))) }; };
   
    #ifndef MAX_NUMERIC_MESSAGE
        #define MAX_NUMERIC_MESSAGE  128
    #endif
   
    #if defined(BOOST_PP_REPEAT) && defined(BOOST_PP_ADD)
        BOOST_PP_REPEAT(BOOST_PP_ADD(MAX_NUMERIC_MESSAGE, 2), DEFINE_NUMERIC_MESSAGE_T,)   
    #endif

    #define NUMERIC_MESSAGE(val)   numeric_message<val, __COUNTER__> BOOST_PP_CAT(__numeric_message__, __COUNTER__);   //counter is evaluated during compile time, not preprocessing time, so it is ok to use it here
    #define NUMERIC_MESSAGE2(val)  FILE_AND_LINE_MESSAGE NUMERIC_MESSAGE(val)   // TODO: currently the line numbers are printed before other stuff
 
#endif  //#ifdef __cplusplus
 
 
 
 

kommentaarium spämmi tõttu ajutiselt välja lülitatud








  Saada kiri