756 questions
1 vote
1 answer
82 views
How to conditionally include a lifetime annotation on a type?
I have an enum like the following: enum E<'a> { #[cfg(feature = "baz")] Foo(&'a str), Bar, } impl E<'_> { /* stuff */ } There is a problem: with feature baz ...
1 vote
1 answer
62 views
How to make UseWindowsForms conditional in csproj?
I have a C# library that I want to publish on Nuget. Currently it only builds if I target net8.0-windows because it has <UseWindowsForms>true</UseWindowsForms>. However, it uses Windows ...
1 vote
1 answer
163 views
How to disable all SIMD related feature macros in clang?
By default, clang defines some SIMD related macros: ~ $ 0 clang++ -dM -E -x c /dev/null | grep -i sse #define __SSE2_MATH__ 1 #define __SSE2__ 1 #define __SSE_MATH__ 1 #define __SSE__ 1 These can be ...
0 votes
0 answers
56 views
Are there good ways define/manage compilation flags for entire solution in Visual Studio for C#?
I'm looking for an elegant way to organize global compilation flags for a Visual Studio solution with multiple projects. I've gotten familiar with the existing configuration manager provided by Visual ...
3 votes
2 answers
118 views
Conditional compilation affecting type parameter
I am writing a Rust crate where I have a struct whose field implements a trait, and I'd like to provide a feature where: #[cfg(not(feature = "dyn"))]: struct field is T, statically ...
0 votes
1 answer
228 views
In Visual Studio 2022, is there a way to output two executables from a single project
I'm using Microsoft Visual Studio 2022 Community edition. I want to create two executables from the same project using conditional attributes. Example: using System; public class MyClass { ...
2 votes
1 answer
70 views
C# conditionals and EF Core generated code fail (bug)?
I have a problem with conditional compiling in EF Core on .NET 8 as described later. It seems as if EF Core code generates SQL that does not take project defines in account. I know how to make a brute ...
0 votes
1 answer
91 views
Rust Conditional flag set by Cargo bench
A function which is only being used with debug assertions is deactivated by: #[cfg(debug_assertions)] fn some_debug_support_fn() {} But this makes cargo bench fail to compile, as it is missing the ...
0 votes
0 answers
85 views
Is there a cleaner way to implement preprocessor-like conditional XAML variants in WPF? [duplicate]
The Problem I extensively use C# preprocessor directives to maintain different code variants during development. For example: #if fix_issue_001 // new implementation #else // original ...
0 votes
1 answer
312 views
How to use variable with #[cfg(...)] attribute?
I would like to use some code only in Debug mode for assertion purposes. I have something like this at the moment: #[cfg(debug_assertions)] let mut thing_initialized = false; for ... { if cfg!(...
1 vote
0 answers
57 views
How to conditionally seriaize nested class with System.Text.Json?
I am looking to serialize a nested class on condition that value of an attribute is different than some custom value. I was looking at: https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-...
1 vote
1 answer
62 views
deduced conflicting types for parameter 'T' (<const int &> vs. <int>)
I have a class Base and MyFunc templates with parameter packs. I have a class Derived, which specifies a const T& type in the parameter pack. template <typename... T> class Base {}; ...
1 vote
1 answer
69 views
How do add a conditional key to an attribute, based on a Cargo feature?
I'm writing a Windows library with FFI to C code, and I'm using the link attribute: #[link(name = "foo")] The above works perfectly. Now, I want to provide a cargo feature which, when ...
-1 votes
1 answer
119 views
Instantiate different classes according to different compilation flag of same header file in c++
I have a class that varies according to a compilation flag. I would like to instantiate both the versions of the class in the same scope. my_class.h #ifndef MY_CLASS_H #define MY_CLASS_H #ifdef ...
-1 votes
2 answers
163 views
Compile lines, only if in Development Environment?
I need some lines of code to only be compiled in Development Environment. They assist in development, and there is quite a few, so manually removing them is not an option. If have looked into ...