compile-time

Flutter: make build-time environment variables available to code

邮差的信 提交于 2021-02-18 06:09:11
问题 How can I have build-time environment variables available to code within a Flutter app? (My specific use case is to inject app version number and commit hash into a debug screen. This information is available at build time, but not at runtime). I had hoped to be able to do something like: flutter run --dart-define=APP_VERSION=0.1.2 And then, const appVersion = String.fromEnvironment('APP_VERSION', defaultValue: 'development'); But this doesn't seem to work (I'm using Flutter 1.12.13+hotfix.5)

Flutter: make build-time environment variables available to code

北城以北 提交于 2021-02-18 06:05:43
问题 How can I have build-time environment variables available to code within a Flutter app? (My specific use case is to inject app version number and commit hash into a debug screen. This information is available at build time, but not at runtime). I had hoped to be able to do something like: flutter run --dart-define=APP_VERSION=0.1.2 And then, const appVersion = String.fromEnvironment('APP_VERSION', defaultValue: 'development'); But this doesn't seem to work (I'm using Flutter 1.12.13+hotfix.5)

Compile-Time Function Execution

廉价感情. 提交于 2021-02-11 05:54:49
问题 Is there a way to perform compile-time function execution in C? With GCC? I've only seen this available using constexpr in C++. 回答1: As long as there are only constants involved in an expression, it will get calculated at compile-time. C++ constexpr is mostly a type safe way of doing so without involving macros. In C, there are only macros. For example: #define CIRCLE_AREA(r) (int32_t)( (double)(r) * (double)(r) * M_PI ) int32_t area = CIRCLE_AREA(5); performs all calculations at compile-time

Why references can't be used with compile time functions?

左心房为你撑大大i 提交于 2021-02-08 05:30:10
问题 I have two snippets. The first snippet: #include <string> template <typename T> constexpr bool foo(T&&) { return false; } int main() { std::string a; if constexpr (foo(a)) { } } The second snippet: #include <string> template <typename T> constexpr bool foo(T&&) { return false; } int main() { std::string a; std::string& x = a; if constexpr (foo(x)) { } } The first one compiles, but the second one does not compile (error message: error: the value of ‘x’ is not usable in a constant expression .

Compile time prime checking

帅比萌擦擦* 提交于 2021-02-06 08:42:13
问题 I need to check is some integer prime in compile time (to put the boolean value as template argument). I've write code that do it well: #include <type_traits> namespace impl { template <int n, long long i> struct PrimeChecker { typedef typename std::conditional< (i * i > n), std::true_type, typename std::conditional< n % i == 0, std::false_type, typename PrimeChecker<n, (i * i > n ) ? -1 : i + 1>::type >::type >::type type; }; template <int n> struct PrimeChecker<n, -1> { typedef void type; }

Why is String.Empty an invalid default parameter?

╄→гoц情女王★ 提交于 2021-02-05 06:52:10
问题 If I type the following: public Response GetArticles(string Filter = String.Empty) { //Body } Visual Studio gives me this error: Default parameter value for 'Filter' must be a compile-time constant If I change the String.Empty to the classic "" it is fixed. But I'm still curious about what is wrong with the String.Empty and its behavior. 回答1: Why is String.Empty an invalid default parameter? Because "Default parameter value for 'Filter' must be a compile-time constant". And String.Empty is

Can I make expressions constexpr?

牧云@^-^@ 提交于 2021-01-28 11:16:46
问题 I recently wrote some code which prints a function result to cout . The result could have been evaluated at compile time, but it wasn't: #include <algorithm> #include <iostream> constexpr unsigned int gcd(unsigned int u, unsigned int v) { // ... } int main() { std::cout << gcd(5, 3) << std::endl; } For whatever bizarre reason, this compiles to: ( clang -O3 -std=c++17 ) main: push r14 push rbx push rax mov edi, 5 mov esi, 3 call gcd(unsigned int, unsigned int) mov esi, eax ... See Compiler

Class in jar not found at runtime, but was used to compile

佐手、 提交于 2021-01-27 14:51:59
问题 After I build this project from an ant file, I recieve a jar that contains all of the classes I built. When I try to run this jar, I get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/SceneGraphObject This error indicates that a one of the jars, specifically the j3dcore.jar from java3d, I am using can not be found. However, this jar is on the classpath when compiling through the ant build into the class files. Why can this class not be found at

Class in jar not found at runtime, but was used to compile

半世苍凉 提交于 2021-01-27 14:37:01
问题 After I build this project from an ant file, I recieve a jar that contains all of the classes I built. When I try to run this jar, I get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/SceneGraphObject This error indicates that a one of the jars, specifically the j3dcore.jar from java3d, I am using can not be found. However, this jar is on the classpath when compiling through the ant build into the class files. Why can this class not be found at

Why 'constexpr' parameters are not allowed?

若如初见. 提交于 2021-01-27 01:50:15
问题 It would be useful to have 'constexpr' parameters in order to distinguish compiler-known values and so to be able detecting errors at compile-time. Examples: int do_something(constexpr int x) { static_assert(x > 0, "x must be > 0"); return x + 5; } int do_something(int x) { if(x > 0) { cout << "x must be > 0" << endl; exit(-1); } return x + 5; } int var; do_something(9); //instance 'do_something(constexpr int x)' and check arg validity at compile-time do_something(0); //produces compiler