News for hackers. Stuff that matters.
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by lbrandy on Tuesday August 08, 2017 @12:36PM (#14959570)
Just so I'm clear, what this appears to be doing is the moral equivalent of a function that asks if some constant equals what we know to be its value (true at compile time)? And then at program-init time (via __attribute__((constructor(101)))) changing the value of the constant in the text section so the test is now false?

If so, that's both quite clever and something I don't think I want in my codebase :P. The good news is I'm pretty sure Daveed's proposal that you mention (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p059...) got support last time it came around EWG so I'm hoping we can just go that way.

Re:Show HN: C++ runtime/compile-time detection in constexpr ... by CuriousThinker on Tuesday August 08, 2017 @01:29PM (#14960191)
Yes that's exactly what's happening under the hood. I'm definitely looking forward to the constexpr operator being accepted!
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by CuriousThinker on Tuesday August 08, 2017 @11:46AM (#14959024)
I discuss the approach more in depth here:

http://saadahmad.ca/detecting-evaluation-context-inside-cons...

Re:Show HN: C++ runtime/compile-time detection in constexpr ... by nickelbox on Tuesday August 08, 2017 @12:26PM (#14959462)
So would a valid tl;dr be, "modify the compiled program to catch any invocations not evaluated at compile time and make them return the correct value?"
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by CuriousThinker on Tuesday August 08, 2017 @12:31PM (#14959529)
That is basically it :)
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by petters on Tuesday August 08, 2017 @02:12PM (#14960767)
Stuff like this shows that we need to introduce even more things into C++. I am not kidding. There are still many things to improve in C++.
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by favorited on Tuesday August 08, 2017 @03:59PM (#14961889)
Luckily, WG21 seems to agree!
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by andrepd on Tuesday August 08, 2017 @11:48AM (#14959051)
In README: "[...] we can choose to implement a runtime specific algorithm while having a different algorithm for doing something at runtime." Typo?
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by CuriousThinker on Tuesday August 08, 2017 @11:57AM (#14959165)
Thanks for catching that!
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by nicwilson on Tuesday August 08, 2017 @09:34PM (#14964791)
As with most things in C++ that looks horribly convoluted for some very simple functionality. In D all we have to do is:

* `if ( __ctfe) { ... }` for compile time

* `if (!__ctfe) { ... }` for runtime

Re:Show HN: C++ runtime/compile-time detection in constexpr ... by VHRanger on Tuesday August 08, 2017 @09:42PM (#14964833)
I don't think it's any secret D does CTFE better than any other language.
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by nicwilson on Wednesday August 09, 2017 @04:52AM (#14966711)
Yeah it never ceases to amaze me the lengths that C++ users goto to try to do things at compile time.
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by logicchains on Wednesday August 09, 2017 @12:17AM (#14965506)
Better than Common Lisp?
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by zerr on Wednesday August 09, 2017 @01:49AM (#14965873)
Does better AND doesn't require the language to be AST :)
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by junke on Wednesday August 09, 2017 @03:53AM (#14966401)
The joke's on you, working with an AST is a treat :)
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by looki on Wednesday August 09, 2017 @09:43PM (#14975574)
Thanks, strangely enough this comment made me read more about D and I'm genuinely excited about getting into this language now
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by billsix on Tuesday August 08, 2017 @07:57PM (#14964201)
In my libbug library, computation at Compile-Time uses the exact same language as the run-time

  {at-both-times
   {define fact
     [|n| (if (= n 0)
              [1]
              [(* n (fact (- n 1)))])]}}

  (pp {at-compile-time-expand   (fact 3)})
  (pp (fact 3))
https://github.com/billsix/bug
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by minipci1321 on Wednesday August 09, 2017 @02:31AM (#14966060)
Why to mlock() the page? And since the code is already specific to linux/gcc/clang, why not to assign the flag to a read-write section (__attribute__((section(name))) -- should allow to get rid of mprotect()?
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by fumigator on Tuesday August 08, 2017 @08:51PM (#14964567)
Typo detected :)

"An approach for runtime dection inside a constexpr function"

https://github.com/SaadAhmad/in_constexpr

Re:Show HN: C++ runtime/compile-time detection in constexpr ... by CuriousThinker on Tuesday August 08, 2017 @08:58PM (#14964603)
Thanks!
Re:Show HN: C++ runtime/compile-time detection in constexpr ... by heja_bruh on Wednesday August 09, 2017 @01:21AM (#14965751)
Another reason why we should not be using c++...