compile-time

Python: Do (explicit) string parameters hurt performance?

心不动则不痛 提交于 2019-12-02 03:31:55
Suppose some function that always gets some parameter s that it does not use. def someFunc(s): # do something _not_ using s, for example a=1 now consider this call someFunc("the unused string") which gives a string as a parameter that is not built during runtime but compiled straight into the binary (hope thats right). The question is: when calling someFunc this way for, say, severalthousand times the reference to "the unused string" is always passed but does that slow the program down? in my naive thoughts i'd say the reference to "the unused string" is 'constant' and available in O(1) when a

Variadic template heterogeneous container

雨燕双飞 提交于 2019-12-02 02:15:17
I need to implement some variadic template container class with heterogeneous elements, which allows to iterate by these elements. My first idea is make class with std::tuple member with variadic arguments, but getting elements from tuple by array-like manner (via loops) is impossible: struct A {void prnt(){std::cout<<"A\n";} }; struct B {void prnt(){std::cout<<"B\n";} }; struct C {void prnt(){std::cout<<"C\n";} }; template<typename...Arg> struct Prc { Prc() : NumElems(sizeof...(Arg)), mems(std::make_tuple(Arg()...)){} int NumElems; std::tuple<Arg...> mems; void process() { for(int i=0; i

Why does an Ada compiler let range violations pass? Why is my type declaration a runtime entity?

我的梦境 提交于 2019-12-02 00:42:12
问题 Why does Ada compiler let range violations pass? It does give warning, but why does it let it pass if it is an error in any case? Is there a practical scenario in which this is a useful behaviour? And most importantly: Why is type declaration a runtime entity? I mean the 3rd line of the code example is something I expect to be evaluated ahead of time. I thought that only the 5th line will "make it" into the executable. Why not? Is that something useful? Am I missing or misinterpreting

Get generic class at compile time

戏子无情 提交于 2019-12-01 21:42:52
While I know you cannot actually get the type of a generic at runtime because of type erasure, I was wondering if it is possible to get it at compile time. class ObjectHandle<T extends ObjType> { T obj; void setObj(T o) { obj = o; } } class ObjType {} class SubObjType extends ObjType {} ... ObjectHandle<SubObjType> handle = new ObjectHandle<SubObjType>(); ... ObjType obj = [method that returns an ObjType]; if(obj instanceof [handle's generic class, here SubObjType]) { handle.setObj(obj); // cast??? } Here the compiler knows the type of the generic of handle and what I want is something so I

Get generic class at compile time

那年仲夏 提交于 2019-12-01 19:46:38
问题 While I know you cannot actually get the type of a generic at runtime because of type erasure, I was wondering if it is possible to get it at compile time. class ObjectHandle<T extends ObjType> { T obj; void setObj(T o) { obj = o; } } class ObjType {} class SubObjType extends ObjType {} ... ObjectHandle<SubObjType> handle = new ObjectHandle<SubObjType>(); ... ObjType obj = [method that returns an ObjType]; if(obj instanceof [handle's generic class, here SubObjType]) { handle.setObj(obj); //

Getting compilation timestamp of a java class

北城余情 提交于 2019-12-01 17:35:55
问题 Is it possible to reliably determine the compilation time stamp of a given class for both java applications running locally and as applets and/or JNLP webapps ? 回答1: According to the Java Virtual Machine Specification, the Class File Format does not require a timestamp of any sort, so the best you could do is check the modification time of the Class or Jar file that contains the class. Unfortunately, filesystem operations, especially between various hosts, might not preserve such timestamps.

In C#, how to restrict who can call a method at compile time

别来无恙 提交于 2019-12-01 10:47:38
In C#, is it possible to restrict who can call a method at compile time? I've looked into directives, but that didn't work since I can't assign values to symbols. #define WHO VisualStudioUser.Current // does not work I also looked into Code Access Security (CAS) but that's runtime enforcement, not compile time. The requirement is to restrict access to a method at compile time for specific developers given the method exists in a pre-compiled assembly. here's more details... I'm building a framework or a series or assemblies for a team of developers. Because of our software license restrictions,

Compile date and time

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 06:41:16
Is there a Java equivalent to the C & C++ compile-time constants __DATE__ and __TIME__. I need to print compile time and version info of the program being compiled. Thanks kodev19 As far as i know, there is nothing like that. But on a running JVM you can get a few informations straight away from the jar using something like the code below (here, the information comes from the Manifest file put in the jar at compilation time (which ever your build system is, Ant or Maven or anything else). Feel free to adapte it (different output, and so on). public String getVersionfinal Class classe) { String

How do I output a compile-time numeric constant during compilation in Visual C++?

允我心安 提交于 2019-12-01 05:38:46
Visual C++ has #pragma message that outputs a string into compiler output . Now I have a factory: template<class Type> CComPtr<Type> CreateComObject() { CComPtr<Type> newObject( new CComObject<Type> ); //do some tuning to the object return newObject; } and I want to output the size of class that is passed to new (namely sizeof( CComObject<Type> ) into the compiler output. Looks like #pragma message only accepts strings. How can I output a compile-time numeric constant? Nawaz If I understood your question correctly, then I think you can do this: template<size_t size> struct overflow{ operator

template metafunction for detecting template specialisations

人走茶凉 提交于 2019-12-01 03:46:56
Inspired by this question , i'm wondering if there is some compile-time check one can introduce to detect if two given template instantiations: template <typename T> class Templ... typedef Templ<std::string> stringInstance; typedef Templ<double> doubleInstance; are constructed from the same definition, or if they are built from different specializations of the Templ template so basically the hypothetical template function will behave like this: template <typename T> class Templ {} template <> class Templ<std::string> {} template <> class Templ<double> {} template <typename T1,typename T2>