Tushar
does anybody have good codes regarding graphs in C programming language
klimi
good codes?
Tushar
Like those that cover the theory part too
klimi
https://github.com/vgautam/graph-algorithms
klimi
something like this?
Tushar
yeah thats good, thank you so much
Пожилой Христос
Hi, how I can connect to PostgresQL or another SQL DB from C++?
Пожилой Христос
I search, but not found lib for it
klimi
https://www.postgresql.org/docs/7.2/libpqplusplus.html something like this?
Пожилой Христос
https://www.postgresql.org/docs/7.2/libpqplusplus.html something like this?
Thanks, but I can't install right it, I use otlv4, but i have error IM002, I don't understand how wright info for contacting to DB
Пожилой Христос
Sorry, i bad speak English
Grigoriy
I don't speak English well either
Anonymous
Please provide a source
<quote>The begin iterator is not decrementable and the behavior is undefined if --container.begin() is evaluated.</quote> from https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator That applies to C++17 and before. For C++20, <quote>A bidirectional iterator r is said to be decrementable if and only if there exists some s such that ++s == r.</quote> from https://en.cppreference.com/w/cpp/iterator/bidirectional_iterator To see why the post C++20 requirement is similar to the C++17 requirements (as in that it leads to UB), look at the requirements for the increment operator for a forward_iterator here - https://en.cppreference.com/w/cpp/iterator/forward_iterator. A forward_iterator is what the C++20 standard uses as a base for defining a bidirectional_iterator concept.
\Device\NUL
Handling big integer
smene
Add the following in your CMakeLists file find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIR}) target_link_libraries(<your executable name from add_executable> ${CURL_LIBRARIES})
set(SOURCE_FILES main.cpp) add_executable(aio_checker ${SOURCE_FILES}) find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIR}) target_link_libraries(${SOURCE_FILES} ${CURL_LIBRARIES}) Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
smene
I don't know where to put it into...
smene
have I to insert the files in the project's directory?
Anonymous
I don't know where to put it into...
Read this https://stackoverflow.com/questions/21314893/what-is-the-default-search-path-for-find-package-in-windows-using-cmake and then this https://cmake.org/cmake/help/latest/command/find_package.html
smene
Thanks mate :)
Grigoriy
Is this correct to transfer shared_from_this() in destructor? class TSomeObject; using TSomeObjectSptr = std::shared_ptr<TSomeObject>; class TOwner { public: virtual ~TOwner(void) = default; virtual void open(const TSomeObjectSptr& ) = 0; virtual void close(const TSomeObjectSptr& ) = 0; }; class TSomeObject : public std::enable_shared_from_this<TSomeObject> { private: TOwner* m_pOwner; public: TSomeObject(TOwner* pOwner) : m_pOwner(pOwner) { m_pOwner->open(shared_from_this()); // OK } virtual ~TSomeObject(void) { m_pOwner->close(shared_from_this()); // Is this OK? } };
Grigoriy
This should be ok as the actual destruction of the shared pointer will happen only after the close function finishes and since close takes a reference, it should be ok.
Clear, but I think that it isn't OK, if TOwner will save shared pointer and continue to use it after TOwner::close.
smene
please, someone help me :(
Anonymous
Clear, but I think that it isn't OK, if TOwner will save shared pointer and continue to use it after TOwner::close.
If that is the case then your interface doesn't reveal it. So you will have to specify it clearly in your question in that case. Even if TOwner saved the shared_ptr, it should do it by calling shared_from_this. If that is the case then it should still be ok
Sid
#include <iostream> using namespace std; int nextprime(int n); int main() { int n; cout << "Enter the no.: "; cin >> n; n = n + 1; cout<<nextprime(n); } int nextprime(int n) { bool found = true; int i; for (;; n++) { for (i = 2; i <= n / 2; i++) { if (n % i == 0) { found = false; break; } } if (found) return n; } }
Sid
Actually i want to get the next prime no. For a number >1
Sid
I want to know what's my fault
Sourav
#include <iostream> using namespace std; int nextprime(int n); int main() { int n; cout << "Enter the no.: "; cin >> n; n = n + 1; cout<<nextprime(n); } int nextprime(int n) { int i; // if(n<2) return 2; for (;; n++) { bool found = true; for (i = 2; i*i <= n; i++) { if (n % i == 0) { found = false; break; } } if (found) return n; } }
Sid
Thanks bro
Sid
Got it 👍
smene
Hi, how do I add libcurl to my Clion project?
coal
Hi, how do I add libcurl to my Clion project?
include it while compiling with -lcurl
coal
and from your source files only include the header
Grigoriy
Is user-defined assignment operator inheritable?
Michel
I'm making my own pair (I really need to) template <typename T> struct pair{ T first; T second; }; how could I make it so that it accepts assign like this: my_pair = {1, 2};?
Michel
Would compilers get that the arguments in order from the array?
coal
Would compilers get that the arguments in order from the array?
you need to define an overload that accepts an std::initializer_list
coal
you need to define an overload that accepts an std::initializer_list
maybe you could find this document useful: https://en.cppreference.com/w/cpp/utility/initializer_list
Eirik
Has anyone here tried the PCC compiler?
Anonymous
you need to define an overload that accepts an std::initializer_list
Not really. std::pair does not have a constructor which takes a std::initializer_list argument. @michelromero Look up "list initialization in C++" in your favourite search engine.
coal
Not really. std::pair does not have a constructor which takes a std::initializer_list argument. @michelromero Look up "list initialization in C++" in your favourite search engine.
I think it's convenient, but maybe I shouldn't have used "need" in that sentence A constructor can also be used for brace initialization
coal
I think it's convenient, but maybe I shouldn't have used "need" in that sentence A constructor can also be used for brace initialization
maybe something like: template<typename T1, typename T2> class Pair { public: T1 first; T2 second; Pair(T1 first, T2 second) : first(first), second(second) {} }; can be called via Pair<int, int> p1 = {1, 2}; as well
coal
std::initializer_list should be used to give priority to a special function during overload resolution when using the {...} syntax, so yeah, not really necessary, however it's a good practice if you want to be explicit in your definitions
Muh
Assalamu'alaikum , #help please help with this problem, the deadline is Tuesday Thanks
Muh
1. Write a program to calculate the addition operation on a 3x3 . matrix 2) Write a program to calculate the multiplication operation on a 3x3 . matrix 3) Give an example program which uses sizeof() to find the sum of the lengths of an array.
Anonymous
std::initializer_list should be used to give priority to a special function during overload resolution when using the {...} syntax, so yeah, not really necessary, however it's a good practice if you want to be explicit in your definitions
It is actually the opposite and is not a good practice. A constructor taking a std::initializer list must be used only when absolutely necessary as this constructor can cause problems with its aggressive matching tendencies. Read Scott Meyers' Effective Modern C++ to understand why
coal
It is actually the opposite and is not a good practice. A constructor taking a std::initializer list must be used only when absolutely necessary as this constructor can cause problems with its aggressive matching tendencies. Read Scott Meyers' Effective Modern C++ to understand why
that's the intention of declaring a std::initializer_list overload in first place. "aggressive matching tendencies," could you elaborate in that sentence? or to the page of the book you're referring to, if possible
coal
This is what I called "list initialization" in my reply and asked the author to look it up.
a code snippet talks more than referencing people, i improved your reply with an example of what you meant
Anonymous
that's the intention of declaring a std::initializer_list overload in first place. "aggressive matching tendencies," could you elaborate in that sentence? or to the page of the book you're referring to, if possible
Which is why you should not use it for data structures like pair or tuple which are meant to emulate an aggregate data type despite having user provided/user declared constructors
Anonymous
a code snippet talks more than referencing people, i improved your reply with an example of what you meant
If you look up "list initialization in C++" in Google like I suggested, there will be 1000s of snippets much better and much more in detail than the snippet you provided.
coal
Which is why you should not use it for data structures like pair or tuple which are meant to emulate an aggregate data type despite having user provided/user declared constructors
this really does not account to the argument you placed first. i earlier specified that an initializer_list takes precedence over any other functions during overload resolution, that's what you meant with "aggresive matching tendencies"?
Anonymous
you provided none.
I don't have to because list initialization is a term in the standard which can be searched for. CPPReference itself has many examples. And braced initialization and list initialization is also a topic that is covered in Scott Meyers' book. I gave the name of the book which should be good enough. There are 42 items in that book. Shouldn't be hard to find the topic that I spoke about by looking into the TOC. You initially gave the OP the wrong answer by suggesting something which should not be done for his use case. I corrected that and gave you tips on what to search for on Google and which book to lookup. You asked for a page number which I can provide but if you can take the pain to do a little research into the table of contents of that book, you can easily find the topic I am referring to. So quit arguing now
Suka
I would like to include libcurl into CMake, I am currently using Clion on Windows.. can anyone help me please?
if you are using msvc compiler try using vcpkg and install curl package. and then follow vcpkg integrate install message to use it in your cmake project. if you are using clang/gcc try install msys2 and install curl pakage goodluck.
Hello, everyone! I am using unordered_map in a hotspot, and I know the maximum total size of this unordered_map in the future(Let's call this size as r ), How many initial bucket count should I set when creating the map in practice? Currently I am using just r , maybe I should set it larger?
Well, I find the answer in stackover flow. But I cannot share the answer here, It is deleted by the robot
If there is anyone have similar question, just google: "Do we need to define bucket count number when construct unordered_map?"
I heard that cpp23 can write member function like python, using self to refer *this, it seems great.
Anonymous
Is there anyone who use red hat linux?
Bereket
I encountered an error when I used string in class I keep getting these errors "incomplete type is not allowed".......can anyone help me out please?
yyrr
James Robert 34 Adam Smith 12 Lily Mia 45 Guys how to read them in text file?
Peace
is there any way to print like this using loops ? The sizeof(char) is : 1 bytes The sizeof(short) is : 2 bytes The sizeof(int) is : 4 bytes The sizeof(long) is : 8 bytes The sizeof(long long) is : 8 bytes The sizeof(float) is : 4 bytes The sizeof(double) is : 8 bytes The sizeof(long double) is : 16 bytes The sizeof(bool) is : 1 bytes
Melbourne Channel
though error: void value not ignored as it ought to be 574 | cpunum = *(key[0]); void functionsomething(void *key) { uint8_t cpunum; cpunum = *(key[0]); // here failed. how do i convert first character to uint8? any c expert here?
꧁𓊈𒆜 ATreeShine 𒆜𓊉꧂
hi
YUSUF
Is there any budy want to learn sfml in c++
Nomid Íkorni-Sciurus
yes
simple answer: you can't advanced answer: you don't want to
it seems I cannot use pastebin...
you tell , i am asking
so I paste the code directly here: #include <boost/core/demangle.hpp> #include <iostream> #include <tuple> #include <typeinfo> #include <utility> template<typename input, std::size_t index = std::tuple_size_v<input> - 1> void show() { if constexpr (index != 0) { show<input, index - 1>(); } using type = std::tuple_element_t<index, input>; std::cout << "The sizeof(" << boost::core::demangle(typeid(type).name()) << ") is : " << sizeof(type) << " bytes\n"; } int main() { using input = std::tuple<char, short, int, long, long long, float, double, long double, bool>; show<input>(); } If you input types by a single tuple, it is easy as above.