language-extension

MSVC direct constructor call extension

被刻印的时光 ゝ 提交于 2019-12-03 14:07:58
In this response , tloveless pointed out that it's possible in MSVC to use this->foo::foo(42); for constructor delegation to directly call a constructor: #include <iostream> struct foo { int m; foo(int p) : m(p) { std::cout << "foo("<<p<<")\n"; } foo() : m(0) { this->foo::foo(42); std::cout << "foo(), " << m << "\n"; } }; int main() { foo f; std::cin.ignore(); } I was surprised that this even compiles in MSVC; clang++, g++ and me agree it's illegal, e.g. [class.ctor]/2 "Because constructors do not have names, they are never found during name lookup" However, MSVC doesn't even emit a warning

Why isn't GeneralizedNewtypeDeriving a Safe Haskell?

牧云@^-^@ 提交于 2019-12-03 11:04:38
问题 From GHC's manual, Section Safe Language: Module boundary control — Haskell code compiled using the safe language is guaranteed to only access symbols that are publicly available to it through other modules export lists. An important part of this is that safe compiled code is not able to examine or create data values using data constructors that it cannot import. If a module M establishes some invariants through careful use of its export list then code compiled using the safe language that

What are the pitfalls of using FlexibleContexts and FlexibleInstances?

那年仲夏 提交于 2019-12-03 10:32:22
问题 Since these flexible contexts and instances aren't available in the Haskell standard, I assume there are potential problems when using them. What are they? Can they lead to some ambiguity, undecidability, overlapping instances, etc.? There is a similar question that asks only about FlexibleInstances , not FlexibleContexts , but the answer only says "that it's safe to use them". 回答1: I once stumbled upon the following. Answering this question, I first tried this code: {-# LANGUAGE

What are the pitfalls of using FlexibleContexts and FlexibleInstances?

隐身守侯 提交于 2019-12-03 01:03:33
Since these flexible contexts and instances aren't available in the Haskell standard, I assume there are potential problems when using them. What are they? Can they lead to some ambiguity, undecidability, overlapping instances, etc.? There is a similar question that asks only about FlexibleInstances , not FlexibleContexts , but the answer only says "that it's safe to use them". Will Ness I once stumbled upon the following. Answering this question , I first tried this code: {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} class (Eq a, Show a) => Genome a where

C++1z Coroutines a language feature?

时光怂恿深爱的人放手 提交于 2019-11-30 20:27:21
Why will coroutines (as of now in the newest drafts for C++1z) be implemented as a core language feature (fancy keywords and all) as opposed to a library extension? There already exist a couple of implementations for them (Boost.Coroutine, etc), some of which can be made platform independent, from what i have read. Why has the committee decided to bake it into the core language itself? I'm not saying they shouldn't but Bjarne Stroustrup himself mentioned in some talk (don't know which one any more) that new features should be implemented in libraries as far as possible instead of touching the

C++1z Coroutines a language feature?

北城余情 提交于 2019-11-30 04:47:58
问题 Why will coroutines (as of now in the newest drafts for C++1z) be implemented as a core language feature (fancy keywords and all) as opposed to a library extension? There already exist a couple of implementations for them (Boost.Coroutine, etc), some of which can be made platform independent, from what i have read. Why has the committee decided to bake it into the core language itself? I'm not saying they shouldn't but Bjarne Stroustrup himself mentioned in some talk (don't know which one any

How would I extend the JavaScript language to support a new operator?

 ̄綄美尐妖づ 提交于 2019-11-28 03:43:06
The answer to the question Is it possible to create custom operators in JavaScript? is not yet , but @Benjamin suggested that it would be possible to add a new operator using third party tools : It is possible to use third party tools like sweet.js to add custom operators though that'd require an extra compilation step. I will take the same example, like in the previous question: (ℝ, ∘), x ∘ y = x + 2y For any two real numbers x and y : x ∘ y is x + 2y that is also a real number. How can I add this operator in my extended JavaScript language? After the following code will be run: var x = 2 , y

What's this C++ syntax that puts a brace-surrounded block where an expression is expected?

╄→гoц情女王★ 提交于 2019-11-27 18:39:02
I came across this weird C++ program. #include <iostream> using namespace std; int main() { int a = ({int x; cin >> x; x;}); cout << a; } Can anyone explain what is going on? What is this construct called? It assigns user input value to a and prints it out. it is done by using a Statement Expression . Statement Expressions are gnu gcc compiler extension are not supported by the C/C++ standards. Hence any code which uses statement expression is non standard conforming and non portable. The IBM IBM XL C/C++ v7.0 also support Statement Expressions & it's doccumentation explains them aptly: