This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sock is bound AF_INET socket, usually SOCK_DGRAM | |
// include struct in_pktinfo in the message "ancilliary" control data | |
setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)); | |
// the control data is dumped here | |
char cmbuf[0x100]; | |
// the remote/source sockaddr is put here | |
struct sockaddr_in peeraddr; | |
// if you want access to the data you need to init the msg_iovec fields | |
struct msghdr mh = { | |
.msg_name = &peeraddr, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
struct Foo { | |
Foo() { std::cout << "Foo...\n"; } | |
~Foo() { std::cout << "~Foo...\n"; } | |
}; | |
struct D { | |
void operator() (Foo* p) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::transform(DataNumbers.begin(), DataNumbers.end(), std::back_inserter(Data), | |
[](const std::string& str) { return std::stoi(str); }); | |
#include <functional> | |
typedef int(*stoi_type)(const std::string&, std::size_t*, int); | |
std::transform(DataNumbers.begin(), DataNumbers.end(), std::back_inserter(Data), | |
std::bind(static_cast<stoi_type>(&std::stoi), | |
std::placeholders::_1, nullptr, 10)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//c++98 | |
template<typename T> | |
class SomeClass; | |
template<typename T> | |
struct MyTypeDef | |
{ | |
typedef SomeClass<T> type; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _POSIX_C_SOURCE 199309L /*note it*/ | |
#include <time.h> | |
#include <stdio.h> | |
int main() | |
{ | |
float f=123.013; | |
for(int j=0; j<2; ++j) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Myclass | |
{ | |
std::string getFirstString() {return string1} | |
std::string getSecondString() {return string2} | |
private: | |
std::string string1; | |
std::string string2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct str{ | |
int len; | |
char s[0]; | |
}; | |
struct foo { | |
struct str *a; | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return size of an array as a compile-time constant. (The | |
// array parameter has no name, because we care only about | |
// the number of elements it contains.) | |
template<typename T, std::size_t N> // see info | |
constexpr std::size_t arraySize(T (&)[N]) noexcept // below on | |
{ // constexpr | |
return N; // and | |
} | |
template<typename Container, typename Index> // final |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto derefLess = // C++14 comparison | |
[](const auto& p1, // function for | |
const auto& p2) // values pointed | |
{ return *p1 < *p2; }; // to by anything | |
// pointer-like |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
//full version | |
template<typename T> | |
struct Allocator | |
{ | |
typedef std::size_t size_type; | |
typedef std::ptrdiff_t difference_type; | |
typedef T* pointer; | |
typedef const T* const_pointer; |
OlderNewer