void

Can a C# lambda expression ever return void?

故事扮演 提交于 2019-11-30 18:32:12
I have the following method, and I want to know if there is anything that can go in place default(void) below because there is a compiler error that says that void is not valid here: private void applyDefaultsIfNecessary(ApplicationConfiguration configuration) { var defaults = new Dictionary<Predicate<ApplicationConfiguration>, Action<ApplicationConfiguration>>() { // { rule, action } - if rule is true, execute action { (c) => c.ConnectionString == null , (c) => c.ConnectionString = "foo" }, { (c) => c.OutputExcelFilePath == null, (c) => c.ConnectionString = "bar" }, { (c) => c.OutputDirectory

Alias template, partial specialization and the invalid parameter type void

此生再无相见时 提交于 2019-11-30 18:31:54
Consider the following code: template<typename F> struct S; template<typename Ret, typename... Args> struct S<Ret(Args...)> { }; template<typename... Args> using Alias = S<void(Args...)>; int main() { S<void(int)> s; Alias<int> alias; } It works fine, as expected and both the line involving S and the one involving Alias define under the hood the same type S<void(int)> . Now, consider the following changes: int main() { S<void(void)> s; // this line compiles Alias<void> alias; // this line does not } I expected it to compile, for reasons that are similar to the ones above mentioned. It goes

Java, recursively reverse an array

[亡魂溺海] 提交于 2019-11-30 17:51:59
I haven't found anything with the specific needs of my function to do this, yes, it is for homework. So I have: public void reverseArray(int[] x) { } Precondition: x.length > 0 The fact that I can't have the function return anything, and the only argument is an array is leaving me stumped. I've tried using loops along with the recursion, but everything I've tried seems to end up with infinite instances of the function being made. I've gotten an idea/suggestion to use another function along with this one, but, how to use the original recursively is beyond me at the moment. Any help is

PostgreSQL functions returning void

╄→гoц情女王★ 提交于 2019-11-30 17:19:55
Functions written in PL/pgSQL or SQL can be defined as RETURNS void . I recently stumbled upon an odd difference in the result. Consider the following demo: CREATE OR REPLACE FUNCTION f_sql() RETURNS void AS 'SELECT NULL::void' -- "do nothing", no special meaning LANGUAGE sql; CREATE OR REPLACE FUNCTION f_plpgsql() RETURNS void AS $$ BEGIN NULL; -- "do nothing", no special meaning END; $$ LANGUAGE plpgsql; The function f_sql() uses the only possible way for a SELECT (as last command) in a SQL function that RETURNS void . I use it just because it is the simplest way for the purposes of this

sizeof(void) equals 1 in C? [duplicate]

耗尽温柔 提交于 2019-11-30 15:46:37
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What is the size of void? Hi all ! I am using gcc for compiling my C programs, just discovered accidentally that the sizeof(void) is 1 byte in C. Is there any explanation for this ? I always thought it to be ZERO (if it really stores nothing) ! Thanks ! 回答1: This is a non standard extension of gcc, but has a rationale. When you do pointer arithmetic adding or removing one unit means adding or removing the object

Can a C++ function be declared such that the return value cannot be ignored?

蓝咒 提交于 2019-11-30 13:10:12
问题 I'm trying to determine whether a C++ function can be declared in such a way that the return value cannot be ignored (ideally detected at compile time). I tried to declare a class with a private (or in C++11, delete d) operator void() to try to catch the implicit conversion to void when a return value is unused. Here's an example program: class Unignorable { operator void(); }; Unignorable foo() { return Unignorable(); } int main() { foo(); return 0; } Unfortunately, my compiler (clang-703.0

Genericity vs type-safety? Using void* in C

主宰稳场 提交于 2019-11-30 12:03:02
问题 Coming from OO (C#, Java, Scala) I value very highly the principles of both code reuse and type-safety. Type arguments in the above languages do the job and enable generic data structures which are both type-safe and don't 'waste' code. As I get stuck into C, I'm aware that I have to make a compromise and I'd like it to be the right one. Either my data structures have a void * in each node / element and I lose type safety or I have to re-write my structures and code for each type I want to

Java generics void/Void types

荒凉一梦 提交于 2019-11-30 11:11:13
问题 I am implementing a ResponseHandler for the apache HttpClient package, like so: new ResponseHandler<int>() { public int handleResponse(...) { // ... code ... return 0; } } but I'd like for the handleResponse function to return nothing, i.e. void . Is this possible? The following does not compile, since void is not a valid Java type: new ResponseHandler<void>() { public void handleResponse(...) { // ... code ... } } I suppose I could replace void with Void to return a Void object, but that's

Does “instanceof Void” always return false?

不想你离开。 提交于 2019-11-30 10:56:40
Can this method return true somehow? public static <T> boolean isVoid(T t) { return t instanceof Void; } Sanjay T. Sharma Yes, but I'm sure that isn't really useful: public static void main(final String[] args) throws Exception { final Constructor c = Void.class.getDeclaredConstructors()[0]; c.setAccessible(true); System.out.println(c.newInstance(null) instanceof Void); } A Void class can't be instantiated so normally your code wouldn't require to deal with Void instances. The above code snippet is just an example of what havoc you can unleash when using reflection... ;-) I fail to see why you

Why can't I explicitly return void from a method?

允我心安 提交于 2019-11-30 10:41:07
void run() { ... if (done) return cancel(); ... } where cancel() return void . This won't compile... and I can almost understand why. But if I want to return a void from a void, why not? Instead, I end up writing something like this: if (done) { cancel(); return; } I'm not looking for code style suggestions, I want to know why Java expressly prohibits this type of void return. Any info is appreciated, thanks. A return statement with an expression returns the value of that expression. The type of cancel() is a void expression - it doesn't have a value. Logically you want to execute cancel() ,