void

Alias template, partial specialization and the invalid parameter type void

核能气质少年 提交于 2019-11-30 03:18:48
问题 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

Genericity vs type-safety? Using void* in C

[亡魂溺海] 提交于 2019-11-30 01:57:33
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 use them with. The complexity of the code is an obvious factor: iterating through an array or a linked

PostgreSQL functions returning void

人走茶凉 提交于 2019-11-30 00:55:26
问题 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

Java generics void/Void types

*爱你&永不变心* 提交于 2019-11-29 23:27:16
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 not really what I want. Question : is it possible to organize this callback situation in such a way that

What's the difference between Void and no parameter?

亡梦爱人 提交于 2019-11-29 21:13:03
I have a class which defines two overloaded methods public void handle(Void e) protected void handle() Obviously they are different, especially handle(Void e) is public . What's the difference between those two? How to call the first method? I am using handle(null) - is this correct? Confusion The first function is a function of a single argument, which must be provided and can only validly take the value null . Any value other than null will not compile. The second function doesn't take any argument and passing null to it would not compile. Void is a special class usually used only for

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

依然范特西╮ 提交于 2019-11-29 16:35:49
问题 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. 回答1: A return statement with an expression returns the value of that expression. The

Does “instanceof Void” always return false?

亡梦爱人 提交于 2019-11-29 16:21:55
问题 Can this method return true somehow? public static <T> boolean isVoid(T t) { return t instanceof Void; } 回答1: 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

Returning From a Void Function in C++

僤鯓⒐⒋嵵緔 提交于 2019-11-29 12:40:55
问题 Consider the following snippet: void Foo() { // ... } void Bar() { return Foo(); } What is a legitimate reason to use the above in C++ as opposed to the more common approach: void Foo() { // ... } void Bar() { Foo(); // no more expressions -- i.e., implicit return here } 回答1: Probably no use in your example, but there are some situations where it's difficult to deal with void in template code, and I expect this rule helps with that sometimes. Very contrived example: #include <iostream>

Is void{} legal or not?

梦想与她 提交于 2019-11-29 10:47:41
问题 This is a follow-up up of this question. In the comments and in the answer it is said more than once that void{} is neither a valid type-id nor a valid expression . That was fine, it made sense and that was all. Then I came through [7.1.7.4.1/2] ( placeholder type deduction ) of the working draft. There it is said that: [...] - for a non-discarded return statement that occurs in a function declared with a return type that contains a placeholder type, T is the declared return type and e is the

Why does C# not allow me to call a void method as part of the return statement?

∥☆過路亽.° 提交于 2019-11-29 10:36:32
问题 I am curious if there is a legitimate reason as to why C# does not support calling a void method as part of the return statement when the calling method's return type is also void. public void MethodA() { return; } public void MethodB() { return MethodA(); } So we would normally see this: public void MethodMeh() { if (expression) { MethodA(); return; } // Do more stuff } ... when we could be using this instead: public void MethodAwesome() { if (expression) return MethodA(); // Do more stuff }