compile-time

Embedding/importing SWC at compile-time in ActionScript, without setting a library path

吃可爱长大的小学妹 提交于 2019-12-24 12:28:01
问题 Hail, Stack! I'm having a little trouble figuring out how to import a SWC file directly in ActionScript, without setting a library path to the file. To exemplify, I need something like this: package { [Embed(source = 'Library.swc')] // This line won't work, of course... import ClassInsideSWC; public class MyClass extends ClassInsideSWC { public function MyClass() { super(); } } } Besides, I don't want to (I can't, in fact) import the SWC by loading it with Loader class. Well, someone knows a

In Rust, can I instantiate my const array without hard-coding in the values? Compile-time evaluation?

一笑奈何 提交于 2019-12-23 12:33:51
问题 I'm trying to instantiate an array in Rust. Here's one way I could do it at runtime: let mut t = [0_u32; 65]; for i in 0..t.len() { t[i] = ((i as f64).sin().abs() * 2.0_f64.powf(32.0)).floor() as u32; } However, since I'm never going to change the values of this array and I'm going to use the values a lot, I thought this might be a good opportunity to explore the cool stuff going on with the const compile-time evaluation work being done in Rust. I could make it compute the array at compile

constexpr does not work/apply inside function call

早过忘川 提交于 2019-12-23 03:25:16
问题 I have implemented a constexpr compile-time hash-function, which works fine (i.e. is evaluated at compile-time) if called as constexpr auto hash = CompileTimeHash( "aha" ); but I need to use it in actual code as an argument to a function as in foo( CompileTimeHash( "aha" ) ); // foo is NOT constexpr For a specific reason, I cannot use the long version constexpr auto hash = CompileTimeHash( "aha" ); foo( hash ); The compiler (VC++) will not compile-time hash in the short (first) case. Is there

constexpr does not work/apply inside function call

廉价感情. 提交于 2019-12-23 03:25:04
问题 I have implemented a constexpr compile-time hash-function, which works fine (i.e. is evaluated at compile-time) if called as constexpr auto hash = CompileTimeHash( "aha" ); but I need to use it in actual code as an argument to a function as in foo( CompileTimeHash( "aha" ) ); // foo is NOT constexpr For a specific reason, I cannot use the long version constexpr auto hash = CompileTimeHash( "aha" ); foo( hash ); The compiler (VC++) will not compile-time hash in the short (first) case. Is there

How to fill array with contents of a template parameter pack?

不羁的心 提交于 2019-12-22 08:09:24
问题 I had nested partially specialized template code working with VS 2015 until I discovered that it was not standards-compliant. I want it to be so I twisted my code to overcome the former issue and also that one and have now hit a hard wall. Using variadic templates and partial specialization I would like to fill an array at compile-time given a fixed set of parameters. What I want to achieve also seems similar to this answer but I did not manage to make it work. Consider the following program:

Finding endian-ness programmatically at compile-time using C++11

安稳与你 提交于 2019-12-22 03:35:15
问题 I have referred many questions in SO on this topic, but couldn't find any solution so far. One natural solution was mentioned here: Determining endianness at compile time. However, the related problems mentioned in the comments & the same answer. With some modifications, I am able to compile a similar solution with g++ & clang++ ( -std=c++11 ) without any warning. static_assert(sizeof(char) == 1, "sizeof(char) != 1"); union U1 { int i; char c[sizeof(int)]; }; union U2 { char c[sizeof(int)];

Is there any advantage in using static_cast rather than C-style casting for non-pointer types?

自作多情 提交于 2019-12-21 07:02:44
问题 I am well aware of the advantage in using static_cast rather than C-style casting for pointer types. If the pointer types are incompatible, then: static_cast will yield a compile-time error at a specific line within the source code C-style casting might lead to a runtime error at a "random" point in the execution of the program But I am unable to find any similar example for non-pointer types. In other words, both casting methods yield the same result for non-pointer types. Is that correct,

The mechanics of extension via free functions or member functions

独自空忆成欢 提交于 2019-12-21 03:56:12
问题 Loads of C++ libraries, the standard included, allow you to adapt your objects for use in the libraries. The choice is often between a member function or a free function in the same namespace. I'd like to know mechanics and constructs the library code uses to dispatch a call which will call one of these "extension" functions, I know this decision has to take place during compile time and involves templates. The following runtime psuedocode is not possible/non-sense, the reasons are out of the

How to reduce compile time with C++ templates

扶醉桌前 提交于 2019-12-21 03:08:52
问题 I'm in the process of changing part of my C++ app from using an older C type array to a templated C++ container class. See this question for details. While the solution is working very well, each minor change I make to the templated code causes a very large amount of recompilation to take place, and hence drastically slows build time. Is there any way of getting template code out of the header and back into a cpp file, so that minor implementation changes don't cause major rebuilds? 回答1: I

Checking whether an object conforms to two separate protocols in Objective-C

会有一股神秘感。 提交于 2019-12-20 10:48:31
问题 In Objective-C when you declare an instance variable you can check if it conforms to a protocol on assignment at compile time like so: id <MyProtocol> variable; Is it possible to check whether an object assigned to the variable conforms to two separate protocols at compile time? As in: id <MyProtocol, MyOtherProtocol> variable; I know I can do runtime checking using conformsToProtocol: and respondsToSelector et al, (which I do before actually using the object for added safety), and I could