All Projects → rhysd → Array_view

rhysd / Array_view

Wrapper for references to array in C++.

Projects that are alternatives of or similar to Array view

Zarr.js
Javascript implementation of Zarr
Stars: ✭ 54 (-6.9%)
Mutual labels:  array
Hello Bar
👋 Greet your visitors with a hello bar
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Material About Library
Makes it easy to create beautiful about screens for your apps
Stars: ✭ 1,099 (+1794.83%)
Mutual labels:  library
Immutable Array Prototype
A collection of Immutable Array prototype methods(Per method packages).
Stars: ✭ 56 (-3.45%)
Mutual labels:  array
Adrestia
APIs & SDK for interacting with Cardano.
Stars: ✭ 56 (-3.45%)
Mutual labels:  library
Pesdk React Native Demo
React Native example for PhotoEditor SDK
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Imageviewer.swift
An easy to use Image Viewer that is inspired by Facebook
Stars: ✭ 1,071 (+1746.55%)
Mutual labels:  library
Lcformvalidation
Javascript based form validation library, third party library / framework agnostic.
Stars: ✭ 58 (+0%)
Mutual labels:  library
Tinf
Tiny inflate library (inflate, gzip, zlib)
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Cordova Mobile Spec
Apache Cordova mobile-spec
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Noexception
Java library for handling exceptions in concise, unified, and architecturally clean way.
Stars: ✭ 56 (-3.45%)
Mutual labels:  library
Countrycodepickerproject
Country Code Picker (CCP) is an android library which provides an easy way to search and select country or international phone code. Also supports Android EditText phone mask and international phone validation.
Stars: ✭ 1,085 (+1770.69%)
Mutual labels:  library
Keyboardhidemanager
Codeless manager to hide keyboard by tapping on views for iOS written in Swift
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Silicompressor
A powerful, flexible and easy to use Video and Image compression library for Android.
Stars: ✭ 1,081 (+1763.79%)
Mutual labels:  library
Thrift
Apache Thrift
Stars: ✭ 8,821 (+15108.62%)
Mutual labels:  library
Sanity Typed Queries
A typed, zero-dependency schema generator and query builder for Sanity.
Stars: ✭ 54 (-6.9%)
Mutual labels:  library
Cdcontainers
Library of data containers and data structures for C programming language.
Stars: ✭ 57 (-1.72%)
Mutual labels:  library
Array Sort
Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
Stars: ✭ 58 (+0%)
Mutual labels:  array
Cartesian Product
PHP - A simple, low-memory footprint function to generate all combinations from a multi-dimensionnal array.
Stars: ✭ 58 (+0%)
Mutual labels:  array
Macfinder
An iOS Library that helps you find the MAC Address of a specific IP
Stars: ✭ 57 (-1.72%)
Mutual labels:  library

Wrapper for Reference to Array

Build Status

References to array are very common in C++ programs. In good old C programs, references to array are represented as a pointer and its length like void f(int const* ptr, size_t const len). In C++, references to array are represented using template parameter like template<size_t N> void f(int (&arr)[N]). And C++ has many useful array classes like std::array, std::vector and so on. array_view can deal all of them with safe and unified way.

#include <iostream>
#include "array_view.hpp"

void show_int_array(arv::array_view<int> view)
{
    std::cout << '{';
    if (!view.empty()) {
        auto itr = view.begin();
        auto const end = view.end();
        while (true) {
            std::cout << *itr;
            if (++itr != end) {
                std::cout << ", ";
            } else {
                break;
            }
        }
    }
    std::cout << "}\n";
}

int main()
{
    int good_old_c_array[] = {1, 2, 3, 4};
    std::array<int, 4> array = {{1, 2, 3, 4}};
    std::vector<int> vector = {1, 2, 3, 4};

    // access arrays with safe and unified way
    show_int_array(good_old_c_array);
    show_int_array(array);
    show_int_array(vector);
    show_int_array({1, 2, 3, 4});
    show_int_array({&good_old_c_array[0], 4});

    return 0;
}

Installation

Copy files in include/ to a directory in include paths.

$ cp include/* path/to/include-dir/

More Usage

When you want to use array_view explicitly, use make_view().

std::vector<int> v = {1, 2, 3};
auto av = arv::make_view(v);

If you want to output array_view, include array_view_output.hpp and just use <<.

#include "array_view_output.hpp"
std::vector<int> v = {1, 2, 3, 4, 5};
std::cout << arv::make_view(v); // "{1, 2, 3, 4, 5}" is output

You can slice array_view to make new sub-array references.

std::vector<int> v = {1, 2, 3, 4, 5};
auto av = arv::make_view(v);
auto sub_av = av.slice(/*position*/ 2, /*length*/ 2);
std::cout << sub_av; // {3, 4}
auto sub_av2 = av.slice(arv::check_bound, /*position*/ 2, /*length*/ 2); // check boundary and may throw an exception
std::cout << sub_av2; // {3, 4}

Why don't you use boost::range?

I use this library in my job. Just try to feel what I feel.

License

This library is distributed under NYSL.

A. This software is "Everyone'sWare". It means: Anybody who has this software can use it as if he/she is the author.

A-1. Freeware. No fee is required. A-2. You can freely redistribute this software. A-3. You can freely modify this software. And the source may be used in any software with no limitation. A-4. When you release a modified version to public, you must publish it with your name.

B. The author is not responsible for any kind of damages or loss while using or misusing this software, which is distributed "AS IS". No warranty of any kind is expressed or implied. You use AT YOUR OWN RISK.

C. Copyrighted to (.......)

D. Above three clauses are applied both to source and binary form of this software.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].