Skip to content

Instantly share code, notes, and snippets.

@tell
Last active August 29, 2015 14:19
Show Gist options
  • Save tell/e038cdd6148488841b40 to your computer and use it in GitHub Desktop.
Save tell/e038cdd6148488841b40 to your computer and use it in GitHub Desktop.
Apple clang 6.1.0 for C++
import subprocess
import pprint
pp = pprint.PrettyPrinter()
flags = ['INCLUDE_CXX11_HEADER', 'NAMESPACE_TR1', 'DECRALATION', 'USE_UMAP']
cxx = 'c++'
cppflags = ['-Wall', '-Wextra']
optflags = ['-O4']
cxxflags = ['-std=c++11']
def build(inputfile, outprefix, extraflags=[]):
sucs = []
for i in range(2 ** len(flags)):
fmt = '{:>0' + str(len(flags)) + 'b}'
bits = fmt.format(i)
selected = map(lambda y: y[1],
filter(lambda x: x[0] == '1', zip(bits, flags)))
fopts = map(lambda x: '-D{}'.format(x), selected)
if len(selected) != 0:
outpostfix = '-'.join(selected)
else:
outpostfix = 'NONE'
args = [cxx] + cppflags + optflags + extraflags + fopts + [inputfile,
'-o', '{outprefix}_{outpostfix}'.format(outprefix=outprefix,
outpostfix=outpostfix)]
rcode = subprocess.call(args)
if rcode == 0:
sucs.append((i, selected, extraflags))
return sucs
def main(inputfile='hoge.cpp'):
sucs = build(inputfile, 'hoge_cxx98')
sucs_cxx11 = build(inputfile, 'hoge_cxx11', cxxflags)
pp.pprint(sucs)
pp.pprint(sucs_cxx11)
if __name__ == '__main__':
main()
#include <stdio.h>
#if defined(INCLUDE_CXX11_HEADER) // (__cplusplus >= 201103L) && !defined(__APPLE__)
#include <functional>
#include <unordered_map>
#endif
#ifdef NAMESPACE_TR1 // (__cplusplus >= 201103L) // || defined(__APPLE__)
#define NAMESPACE_std std::tr1
#define NAMESPACE_BEGIN namespace tr1 {
#define NAMESPACE_END }
#else
#define NAMESPACE_std std
#define NAMESPACE_BEGIN
#define NAMESPACE_END
#endif
template<class T, class U>
struct A {
friend bool operator==(const A&, const A&) {
return true;
}
};
struct B {};
struct C {};
namespace std {
NAMESPACE_BEGIN
#ifdef DECRALATION // !defined(INCLUDED_CXX11_HEADER)
template<class T> struct hash;
template<class T>
struct hash {
size_t operator()(const T&) const {
return -1;
}
};
#endif
template<class T, class U>
struct hash< A<T, U> > {
size_t operator()(const A<T, U>&) const {
return 0;
}
};
NAMESPACE_END
}
int main()
{
printf("__cplusplus = %ld\n", __cplusplus);
typedef NAMESPACE_std::hash< A<B, C> > hash;
hash h;
A<B, C> x;
printf("h: %lu\n", h(x));
#ifdef USE_UMAP
typedef NAMESPACE_std::unordered_map< A<B, C>, size_t> map;
map m;
m.insert(std::make_pair(x, 0));
printf("m: %lu\n", m[x]);
#endif
}
PYTHON = python
all:
$(PYTHON) build.py | tee result.txt
clean:
$(RM) hoge_* *~
[(2, ['DECRALATION'], []),
(6, ['NAMESPACE_TR1', 'DECRALATION'], []),
(8, ['INCLUDE_CXX11_HEADER'], []),
(9, ['INCLUDE_CXX11_HEADER', 'USE_UMAP'], []),
(14, ['INCLUDE_CXX11_HEADER', 'NAMESPACE_TR1', 'DECRALATION'], [])]
[(2, ['DECRALATION'], ['-std=c++11']),
(6, ['NAMESPACE_TR1', 'DECRALATION'], ['-std=c++11']),
(8, ['INCLUDE_CXX11_HEADER'], ['-std=c++11']),
(9, ['INCLUDE_CXX11_HEADER', 'USE_UMAP'], ['-std=c++11']),
(14,
['INCLUDE_CXX11_HEADER', 'NAMESPACE_TR1', 'DECRALATION'],
['-std=c++11'])]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment