c++11 - Is there a way to print a constexpr string during compiletime? -


i'm trying following (only relevant parts of code below):

template<typename containertype> struct iscontainercheck : is_container<containertype> {    static constexpr char* err_value = "type not container model"; };  namespace _check_concept {     template<typename resulttype>     struct run {         constexpr static int apply() {             static_assert(false, iscontainercheck<resulttype>::err_value)             return 0;         }     };      template<>     struct run<true_t> {         constexpr static int apply() {             return 0;         }     }; } 

this fails because static_assert allows literals printed. same boost_static_assert_msg macro.

so question - there way output constexpr string during compilation? if there gcc extension providing functionality great.

used compiler gcc 4.8.1

gcc not provide such mechanism want. not need if able refactor code illustrated in following program. (i have filled in few gaps give compilable example):

#include <type_traits> #include <vector>  template<typename containertype> struct is_container {     static bool const value = false; };  template<> struct is_container<std::vector<int>> {     static bool const value = true; };  template<typename containertype> struct iscontainercheck // : is_container<containertype> <- uneccessary {     static_assert(is_container<containertype>::value,          "type not container model"); };  namespace _check_concept {     template<typename resulttype>     struct run {         constexpr static int apply() {             return (iscontainercheck<resulttype>(),0);         }     };      // no such specialization necessary. delete it.     // template<>     // struct run<true_t> {     //    constexpr static int apply() {     //        return 0;     //    }     //}; }  using namespace _check_concept;  int main(int argc, char **argv) {     auto verdict0 = run<std::vector<int>>::apply();     (void)verdict0;     // following line static_assert: "type not container model"     auto verdict1 = run<float>::apply();     (void)verdict1;     return 0; } 

in specialization _check_concept::struct run<true_t> presume true_t not alias or equivalent of std::true_type, rather place-holder some resulttype container type. test program shows, no such specialization necessary, because iscontainercheck<resulttype>() static_assert, or not, depending on resulttype, in unspecialized run<resulttype>::apply().


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -