compile-time

The mechanics of extension via free functions or member functions

自作多情 提交于 2019-12-03 12:16:27
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 scope of this question. if Class A has member function with signature FunctionSignature choose &A

Confusion about constant expressions

孤者浪人 提交于 2019-12-03 10:30:45
This is some kind of follow-up for this topic and deals about a little part of it. As with the previous topic, let's consider that our compiler has constexpr functions for std::initializer_list and std::array . Now, let's go straight to the point. This works : #include <array> #include <initializer_list> int main() { constexpr std::array<int, 3> a = {{ 1, 2, 3 }}; constexpr int a0 = a[0]; constexpr int a1 = a[1]; constexpr int a2 = a[2]; constexpr std::initializer_list<int> b = { a0, a1, a2 }; return 0; } This does not : #include <array> #include <initializer_list> int main() { constexpr std:

Force pre-computation of a constant

喜你入骨 提交于 2019-12-03 10:03:51
问题 I have a constant declaration in Haskell -- can I force this to be evaluated ahead of time? I'm seeing some code that looks roughly like, myList = [(a, b), (c, d)] ... map (f . fst) myList take time in the fst call when I profile it (it does have 168M calls). The binary representation of myList is quite small, and could be, for example, copied into global memory [if this were a C program]. I'm compiling with -O3 -optc-O3 of course. Thanks very much! Generating Lift instances for a custom type

How compile time recursion works?

狂风中的少年 提交于 2019-12-03 09:27:29
问题 I found a code here Printing 1 to 1000 without loop or conditionals Can someone please explain how compile time recursion works, couldn't find it in google // compile time recursion template<int N> void f1() { f1<N-1>(); cout << N << '\n'; } template<> void f1<1>() { cout << 1 << '\n'; } int main() { f1<1000>(); } Thank you! 回答1: It repeatedly instantiates the f1<N> template with decreasing values for N ( f1<N>() calls f1<N-1> and so on). The explicit specialization for N==1 ends the

How to reduce compile time with C++ templates

≯℡__Kan透↙ 提交于 2019-12-03 09:23:14
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? I think the general rules apply. Try to reduce coupling between parts of the code. Break up too large template

Compile time and Run time in perl

╄→гoц情女王★ 提交于 2019-12-03 09:04:25
I am reading this document to understand the life cycle of a Perl program. I am unable to figure out when RUN time and when COMPILE time events occur while running a perl script on a command line like this: perl my_script.pl perl script.pl will compile script.pl then execute script.pl . Similarly, require Module; will compile Module.pm then execute Module.pm . If the compiler encounters a BEGIN block, it will execute the block as soon as the block is compiled. Keep in mind that use is a BEGIN block consisting of a require and possibly a import . For example, # script.pl use Foo; my $foo = Foo-

Cycle inside ; building could produce unreliable results: Xcode 10 Error

僤鯓⒐⒋嵵緔 提交于 2019-12-03 01:49:10
问题 I am trying to move to the new build system when compiling with Xcode 10. However, it gives following error: Cycle details: → Target 'project' : LinkStoryboards Target 'project' has compile command with input '/Users/project/Commons/Components/ScreenshotSharing/ViewController/AppShare.storyboard' Target 'project' : ValidateEmbeddedBinary /Users/project/Xcode/DerivedData/project-hgqvaddkhmzxfkaycbicisabeakv/Build/Products/Debug-iphoneos/project.app/PlugIns/stickers.appex Target 'project' has

Force pre-computation of a constant

女生的网名这么多〃 提交于 2019-12-02 23:19:39
I have a constant declaration in Haskell -- can I force this to be evaluated ahead of time? I'm seeing some code that looks roughly like, myList = [(a, b), (c, d)] ... map (f . fst) myList take time in the fst call when I profile it (it does have 168M calls). The binary representation of myList is quite small, and could be, for example, copied into global memory [if this were a C program]. I'm compiling with -O3 -optc-O3 of course. Thanks very much! Generating Lift instances for a custom type Any expression given to the lift call in sclv's answer must be an instance of Lift. There's a library

Cycle inside ; building could produce unreliable results: Xcode 10 Error

删除回忆录丶 提交于 2019-12-02 15:22:39
I am trying to move to the new build system when compiling with Xcode 10. However, it gives following error: Cycle details: → Target 'project' : LinkStoryboards Target 'project' has compile command with input '/Users/project/Commons/Components/ScreenshotSharing/ViewController/AppShare.storyboard' Target 'project' : ValidateEmbeddedBinary /Users/project/Xcode/DerivedData/project-hgqvaddkhmzxfkaycbicisabeakv/Build/Products/Debug-iphoneos/project.app/PlugIns/stickers.appex Target 'project' has process command with input '/Users/project/Resources/Info.plist' Target 'project' has compile command

Python: Do (explicit) string parameters hurt performance?

我只是一个虾纸丫 提交于 2019-12-02 10:41:14
问题 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