Skip to content

Instantly share code, notes, and snippets.

@rikusouda
rikusouda / ConstTest.cpp
Last active June 29, 2018 01:28
C++のconst動作を実際に検証
#include <vector>
int main(int argc, const char * argv[]) {
// Pointer
{
const std::vector<int>* pArray = new std::vector<int>();
std::vector<int> const* pArray2 = new std::vector<int>();
std::vector<int>* const pArrayMutable = new std::vector<int>();
pArray->push_back(9999); // error
@rikusouda
rikusouda / ObjcInCppVector.mm
Created June 16, 2018 12:43
In ARC, C++ std::vector has Objective-C instances
#import <Foundation/Foundation.h>
#include <string>
#include <vector>
@interface ObjcClass: NSObject
@property (nonatomic, readonly) NSString *name;
- (instancetype)initWithName:(NSString *)name;
- (void)speak;
@end
#import <Foundation/Foundation.h>
#include <string>
#include <memory>
@interface ObjcClass: NSObject
@property (nonatomic, readonly) NSString *string;
- (instancetype)initWithString:(NSString *)string;
- (void)speak;
@end
@rikusouda
rikusouda / CppInObjc.mm
Created June 3, 2018 08:40
Instance of C++ into property of Objective-C
#import <Foundation/Foundation.h>
#include <string>
#include <memory>
class CppClass {
private:
std::wstring m_value;
public:
CppClass(std::wstring& value): m_value(value){ }
std::wstring& value() { return m_value; }
@rikusouda
rikusouda / ZunDokoKiyoshi.swift
Last active April 9, 2017 04:29
クロージャーの再帰を使ったズンドコキヨシ
import Foundation
enum ZunDoko :Int {
case ズン
case ドコ
static func createRandom() -> ZunDoko {
return ZunDoko(rawValue: Int(arc4random_uniform(2)))!
}
}