library-design

What purpose does `gsl::string_span` aim at?

自古美人都是妖i 提交于 2020-02-04 02:54:29
问题 During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions: Why is gsl::string_span provided where gsl::span already works well? Why is gsl::zstring_span provided where std::string is already guaranteed to be null-terminated since C++11? Any illustrating situations will be highly appreciated. 回答1: span("Hi") is {'H', 'i', '\0'} whereas string_span("Hi") is {'H', 'i'} . string_span checks for the terminating null character and does not include it in the span.

The mechanics of extension via free functions or member functions

独自空忆成欢 提交于 2019-12-21 03:56:12
问题 Loads of C++ libraries, the standard included, allow you to adapt your objects for use in the libraries. The choice is often between a member function or a free function in the same namespace. I'd like to know mechanics and constructs the library code uses to dispatch a call which will call one of these "extension" functions, I know this decision has to take place during compile time and involves templates. The following runtime psuedocode is not possible/non-sense, the reasons are out of the

Why generic IList<> does not inherit non-generic IList

眉间皱痕 提交于 2019-12-17 10:55:08
问题 IList<T> does not inherit IList where IEnumerable<out T> inherits IEnumerable . If out modifier are the only reason then why most of the implementation of IList<T> (e.g. Collection<T> , List<T> ) implements IList interface. So any one can say OK, if that statements is true for all implementation of IList<T> then directly cast it to IList when necessary. But problem is that though IList<T> does not inherit IList so it is not guaranteed that every IList<T> object are IList . Moreover using

Why the std::this_thread namespace? [closed]

梦想的初衷 提交于 2019-12-10 06:34:15
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Is there a technical reason for the std::this_thread namespace? Why could the members of this namespace not have been implemented as

What's the purpose of Function.const?

笑着哭i 提交于 2019-12-10 00:50:51
问题 It is in ScalaDoc but without much documentation. It seems that it always returns the first parameter. Function.const(1)(2) for instance returns 1 . Why does it exist and why is it useful? 回答1: To give a more theoretical answer: const is the K combinator of the SKI calculus. It pops sometimes up when you work with quite abstract concepts where you don't have much "to work with". Consider a (Haskell style) Functor trait: trait Functor[F[_]] { def fmap[A,B](f:A=>B, fa: F[A]):F[B] //(<$) in

Architecture of some reusable code

≯℡__Kan透↙ 提交于 2019-12-06 11:01:35
I am writing a number of small, simple applications which share a common structure and need to do some of the same things in the same ways (e.g. logging, database connection setup, environment setup) and I'm looking for some advice in structuring the reusable components. The code is written in a strongly and statically typed language (e.g. Java or C#, I've had to solve this problem in both). At the moment I've got this: abstract class EmptyApp //this is the reusable bit { //various useful fields: loggers, db connections abstract function body() function run() { //do setup this.body() //do

Why the std::this_thread namespace? [closed]

╄→гoц情女王★ 提交于 2019-12-05 12:33:16
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Is there a technical reason for the std::this_thread namespace? Why could the members of this namespace not have been implemented as static members of the std::thread class? Howard Hinnant From the original proposal , the way to get a

The mechanics of extension via free functions or member functions

自作多情 提交于 2019-12-03 12:16:27
Loads of C++ libraries, the standard included, allow you to adapt your objects for use in the libraries. The choice is often between a member function or a free function in the same namespace. I'd like to know mechanics and constructs the library code uses to dispatch a call which will call one of these "extension" functions, I know this decision has to take place during compile time and involves templates. The following runtime psuedocode is not possible/non-sense, the reasons are out of the scope of this question. if Class A has member function with signature FunctionSignature choose &A

Why do standard classes sometimes have seemingly unrelated methods?

£可爱£侵袭症+ 提交于 2019-12-02 06:11:09
问题 While studying the standard Java library and its classes, i couldn't help noticing that some of those classes have methods that, in my opinion, have next to no relevance to those classes' cause. The methods i'm talking about are, for example, Integer#getInteger, which retrieves a value of some "system property", or System#arraycopy, whose purpose is well-defined by its name. Still, both of these methods seem kinda out of place, especially the first one, which for some reason binds working

Why do standard classes sometimes have seemingly unrelated methods?

99封情书 提交于 2019-12-02 01:45:30
While studying the standard Java library and its classes, i couldn't help noticing that some of those classes have methods that, in my opinion, have next to no relevance to those classes' cause. The methods i'm talking about are, for example, Integer#getInteger , which retrieves a value of some "system property", or System#arraycopy , whose purpose is well-defined by its name. Still, both of these methods seem kinda out of place, especially the first one, which for some reason binds working with system resources to a primitive type wrapper class. From my current point of view, such method