Javascript in a View Component

What I decided to do is write a ScriptTagHelper that provides an attribute of “OnContentLoaded”. If true, then I wrap the inner contents of the script tag with a Javascript function to execute once the document is ready. This avoids the problem with the jQuery library having not loaded yet when the ViewComponent’s script fires. … Read more

How does “using std::swap” enable Argument-Dependent Lookup (ADL)?

Just wanted to add why this idiom is used at all, which seemed like the spirit of the original question. This idiom is used within many std library classes where swap is implemented. From http://www.cplusplus.com/reference/algorithm/swap/: Many components of the standard library (within std) call swap in an unqualified manner to allow custom overloads for non-fundamental … Read more

stdout vs console.write in c#

In languages like C and C++, there is a global variable with the name stdout, which is a pointer to the standard output stream. Thus, stdout has become a commonly used abbreviation for “standard output stream” even outside the context of the C language. Now, what does C# do? Let’s have a look at the … Read more

A shared recursive mutex in standard C++

Recursive property of the mutex operates with the term “owner“, which in case of a shared_mutex is not well-defined: several threads may have .lock_shared() called at the same time. Assuming “owner” to be a thread which calls .lock() (not .lock_shared()!), an implementation of the recursive shared mutex can be simply derived from shared_mutex: class shared_recursive_mutex: … Read more

How to concatenate static strings at compile time?

I recently revisited this problem, and found that the previous answer I gave produced ridiculously long compile times when concatenating more than a handful of strings. I have produced a new solution which leverages constexpr functions to remove the recursive templates responsible for the long compilation time. #include <array> #include <iostream> #include <string_view> template <std::string_view … Read more