c++ - g++ template error Small_size -


i working on latest revision of c++ programming language (think it's 5) , run problem g++ version 5.2.

my code variation of small_size template chap 24.

#include <iostream>  template<int n> bool is_small () {   std::cerr << sizeof(n) << std::endl;   std::cerr << n << std::endl;    return n <= 255; }   bool ism (int i_n) {   return i_n <= 255; }   int main () {   std::cout << "hallo welt" << std::endl;    std::cout << 0 << " " << is_small<0> << std::endl;   std::cout << 255 << " " <<is_small<255> << std::endl;   std::cout << -4100000000 << " " << is_small<-4100000000> << std::endl;   std::cout << 256 << " " << is_small<256> << std::endl;   std::cout << 256 << " " << ism(256) << std::endl;   std::cout << 256 << " " << (256 <= 255) << std::endl; } 

when compile it, it's ok. when run thing, seems broken.

[cpp11@hydra src]$ cat ~/bin/g14 #!/bin/bash g++-52 -std=c++14 "${1}.c" -l$libpath -o "$1" [cpp11@hydra src]$ g14 konzept_small [cpp11@hydra src]$ ./konzept_small  hallo welt 0 1  255 1 -4100000000 1 256 1                    //1 256 0 256 0 [cpp11@hydra src]$ 

my problem that:

  1. the result 256 , higher wrong. see comment //1
  2. there no output of template code on cerr

i started version without cerr, got wrong template result.

i removed constexpr template, no change.

so added last step cerr see whats wrong.

any ideas?

you not calling is_small<n>, printing out address. need change code to

std::cout << 0 << " " << is_small<0>() << std::endl; std::cout << 255 << " " <<is_small<255>() << std::endl; std::cout << -4100000000 << " " << is_small<-4100000000>() << std::endl; std::cout << 256 << " " << is_small<256>() << std::endl; 

note added (). not sure why getting output though, sure running same code posted?


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -