Posts

Showing posts from April, 2021

Why is unique_ptr not equality_comparable_with nullptr_t in C++20?

46 4 Working with C++20's concept s I noticed that std::unique_ptr appears to fail to satisfy the std::equality_comparable_with<std::nullptr_t,...> concept. From std::unique_ptr 's definition, it is supposed to implement the following when in C++20: template<class T1, class D1, class T2, class D2> bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template <class T, class D> bool operator==(const unique_ptr<T, D>& x, std::nullptr_t) noexcept; This requirement should implement symmetric comparison with nullptr -- which from my understanding is sufficient for satisfying equality_comparable_with . Curiously, this issue appears to be consistent on all the major compilers. The following c...

Why is the string '3' not matched in a case statement with the range ('0'…'10')?

28 1 When I try to match for the string '3' in a case statement, it matches if the range goes up to '9', but not '10'. I'm guessing it has something to do with the triple equals operator, but I don't know the exact reason why it can be in the range, but not matched. Here is an IRB run documenting both cases that work (with '9'), and don't work (with '10'): case '3' when ('0'...'9') puts "number is valid" else puts "number is not valid" end Output: number is valid case '3' when ('0'...'10') puts "number is valid" else puts "number is not valid" end Output: number is not valid The methods that I used as ...

Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed in your Gemfile [duplicate]

16 4 This question already has answers here : Bundler::GemNotFound: Could not find mimemagic-0.3.5 in any of the sources on Rails project with Docker (2 answers) Closed 26 days ago . Today I tried to build a docker for my rails 6.1.0 with active storage, I got the following error: Your bundle is locked to mimemagic (0.3.5), but that version could not be found in any of the sources listed...

Getting Uncaught TypeError: path.split is not a function in react

19 1 I'm trying to do validations for my form in react. I chose "react-hook-form" library. But I'm constantly getting error "Path.split is not a function. Even after using the default example given in their website, I'm getting the same error. This is the default code given in the official site. import React from "react"; import { useForm } from "react-hook-form"; export default function App() { const { register, handleSubmit, watch, errors } = useForm(); const onSubmit = data => console.log(data); console.log(watch("example")); // watch input value by passing the name of it return ( {/* "handleSubmit" will validate your inputs before invoking "onSubmit" */} <form onSu...

Why does “&& true” added to a constraint make a function template a better overload?

26 1 Consider the following two overloads of a function template foo : template <typename T> void foo(T) requires std::integral<T> { std::cout << "foo requires integral\n"; } template <typename T> int foo(T) requires std::integral<T> && true { std::cout << "foo requires integral and true\n"; return 0; } Note the difference between the two constraints: the second has an extra && true . Intuitively speaking, true is redundant in a conjunction (since X && true is just X ). However, it looks like this makes a semantic difference, as foo(42) would call the second overload. Why is this the case? Specifically, why is the second function template a better overload? ...

Chart JS +ng2-charts not working on Angular+2

16 1 Hello developers i have been literally the whole day trying to implement charts on my proyect , but following the official docs there is not way i could rid off this error : ERROR in ./node_modules/ng2-charts/__ivy_ngcc__/fesm2015/ng2-charts.js 317:8-21 "export 'pluginService' was not found in 'chart.js' node_modules/ng2-charts/lib/base-chart.directive.d.ts:4:59 - error TS2305: Module '"../../chart.js/types/index.esm"' has no exported member 'ChartPoint'. 4 import { ChartConfiguration, ChartDataSets, ChartOptions, ChartPoint, ChartType, PluginServiceGlobalRegistration, PluginServiceRegistrationOptions } from 'chart.js'; ~~~~~~~~~~ n...

How to flatten the nested std::optional?

19 2 note: this question was briefly marked as a duplicate of this, but it is not an exact duplicate since I am asking about std::optionals specifically. Still a good question to read if you care about general case. Assume I have nested optionals, something like this(dumb toy example): struct Person{ const std::string first_name; const std::optional<std::string> middle_name; const std::string last_name; }; struct Form{ std::optional<Person> person; }; and this spammy function: void PrintMiddleName(const std::optional<Form> form){ if (form.has_value() && form->person.has_value() && form->person->middle_name.has_value()) { std::cout << *(*(*form).person).middle_name << std::endl; }...

Can't use public nested class as private method parameter

13 3 In the following code: class Outer { private: void f_private(Outer::Inner in); // Wrong public: class Inner {}; void f_public(Outer::Inner in); // OK }; f_private() cannot use nested class Outer::Inner as parameter type. But it's ok to do so in f_public() . Can someone explain to me in what rule this is based on, and what's the benefit it? c++ inner-classes access-modifiers public-members Share Improve this question Follow ...

Does casting to or from a double and a float preserve infinity and NaN?

23 When casting double infinity to float and vice versa, will it still be infinity? Is it the same with NaN? c++ floating-point nan Share Improve this question Follow edited Apr 7 at 5:03 Peter Cordes 242k 34 34 gold badges 417 417 silver badges 593 593 bronze badges ...