My goal is to separate all vectorclass-library typenames to a separate namespace, so that vcl::Vec4i will compile, but Vec4i won't. I tried to use example from manual, however it's not working.
Failed attempt following the manual:
#include <iostream>
#include "vcl/vectorclass.h"
#define VCL_NAMESPACE vcl
using namespace vcl; //error
int main() {
vcl::Vec4i vec; //error
Vec4i vec; //still compiles
return 0;
}
Failure message:
root@vlad:/avx_vcl clang++ -std=c++17 -mavx -o test main.cpp
main.cpp:4:17: error: expected namespace name
using namespace vcl;
^
main.cpp:6:2: error: use of undeclared identifier 'vcl'
vcl::Vec4i vec;
^
2 errors generated.
Desired result:
#define VCL_NAMESPACE vcl
int main() {
vcl::Vec4i vec; //compiles
Vec4i vec; //won't compile
return 0;
}
What should I change?
As noted in chapter
2.7 Using a namespace, you need todefine VCL_NAMESPACEbefore including anyvclheaders, directly or indirectly, so change the order to:If we look inside
vectori128.hwhich definesVec4iwe see that all of the definitions in the file are surrounded by an#ifdef VCL_NAMESPACEpair:So, what happens is that if you don't define
VCL_NAMESPACEbefore including any of those headers, it will not put them in the namespace you've selected.Note - You need to put this
#define VCL_NAMESPACE vclfirst in all your files that include anyvclheader, directly or indirectly. It may be easiest to give the compiler the instruction to just define it always.g++example: