A competitive programming helper tool, which packages included libraries into a single file, suitable for online judges.

Overview

cpack

Cpack is a competitive programming helper tool, which packages the main source file along with included libraries into a single file, suitable for online judges.

The problem

You want to make a library of common algorithms and use it while solving some tasks. But, as you may know, having tens of algorithms clustered in one file is messy (and unmaintainable). So you may want to try to split them, but here competitive programming hits you; you can't submit more than one file.

The solution

The next shell block contains your main source file which uses system libraries bits/stdc++.h and algorithm and your own library example_header.hpp. Libraries you don't want packaged must be specified in a protected block, check out the example. This block will allow language servers to function properly while you develop the source, and prevent cpack from packaging system headers, which would prevent portability.

$ cat example_main_source.cpp

// this is how you include a system library, you don't want packaged
#ifdef COMP_PROG_DEPLOY
#pragma DELETETHISPREFIX #include <bits/stdc++.h>
#else
#include <bits/stdc++.h>
#endif

// one more system library, just for the demo
#ifdef COMP_PROG_DEPLOY
#pragma DELETETHISPREFIX #include <algorithm>
#else
#include <algorithm>
#endif

// this is how you include your own library you want packaged
#include "example_header.hpp"

//twice to demonstrate functionality of #pragma once
#include "example_header.hpp" 

using namespace std;

int main(){
    cout << header_fn() << endl;
}

Also, check out the simple header for demonstration purposes. Notice that it uses #pragma once; since this script uses gcc compiler internally, you can include all your standard preprocessor functions and they will function properly.

$ cat example_header.hpp

#pragma once

int header_fn(){
    return 42;
}

Run cpack utility and observe the packaged source, which can be easily submitted to online judges.

$ cpack example_main_source.cpp
Packaging of source done!   (example_main_source.cpp.cpack.cpp)

$ cat example_main_source.cpp.cpack.cpp
 #include <bits/stdc++.h>
 #include <algorithm>

int header_fn(){
    return 42;
}
using namespace std;
int main(){
    cout << header_fn() << endl;
}

Compiling and running the packaged source.

$ g++ example_main_source.cpp.cpack.cpp
$ ./a.out
42

The main limitation of this system is that you have to decide whether to include a header file or not. This has to be done since some headers are non-portable, and can't be expanded on your local pc and then submitted to online judges.

Setup: (tested on linux system with gcc 10.2.0 and bash 5.1.0)

  1. Download/clone the repo (or just the cpack script) into some folder
  2. Add a symbolic link to the cpack script or alias it in your .bashrc

How to include headers from other locations?

Add your location to default search path in current shell:

$ ls
example_main_source.cpp
$ export CPLUS_INCLUDE_PATH=~/my_library_location/
$ cpack example_main_source.cpp
Packaging of source done!   (example_main_source.cpp.cpack.cpp)

Contact

Feel free to contact me with suggestions, questions, etc, at petar.mihalj.other ATCHAR pm.me

Owner
PetarMihalj
PetarMihalj
Helper plugin for analyzing UEFI firmware

bn-uefi-helper Description Helper plugin for analyzing UEFI firmware. This plugin contains the following features: Apply the correct prototype to the

Brandon Miller 73 Aug 1, 2022
Suman Raj Khanal 7 Nov 24, 2021
A fast single-producer, single-consumer lock-free queue for C++

A single-producer, single-consumer lock-free queue for C++ This mini-repository has my very own implementation of a lock-free queue (that I designed f

Cameron 2.7k Aug 5, 2022
A bounded single-producer single-consumer wait-free and lock-free queue written in C++11

SPSCQueue.h A single producer single consumer wait-free and lock-free fixed size queue written in C++11. Example SPSCQueue<int> q(2); auto t = std::th

Erik Rigtorp 509 Aug 7, 2022
C++20's jthread for C++11 and later in a single-file header-only library

jthread lite: C++20's jthread for C++11 and later A work in its infancy. Suggested by Peter Featherstone. Contents Example usage In a nutshell License

Martin Moene 44 Jul 16, 2022
Kokkos C++ Performance Portability Programming EcoSystem: The Programming Model - Parallel Execution and Memory Abstraction

Kokkos: Core Libraries Kokkos Core implements a programming model in C++ for writing performance portable applications targeting all major HPC platfor

Kokkos 1.1k Aug 10, 2022
THIS REPOSITORY HAS MOVED TO github.com/nvidia/cub, WHICH IS AUTOMATICALLY MIRRORED HERE.

About CUB CUB provides state-of-the-art, reusable software components for every layer of the CUDA programming model: Device-wide primitives Sort, pref

NVIDIA Research Projects 63 Jul 4, 2022
Single header asymmetric stackful cross-platform coroutine library in pure C.

minicoro Minicoro is single-file library for using asymmetric coroutines in C. The API is inspired by Lua coroutines but with C use in mind. The proje

Eduardo Bart 313 Aug 15, 2022
Fork of rpmalloc to be used with single thread applications and old C compilers

srpmalloc - Small rpmalloc This is a fork of rpmalloc, with the intent to be used in single threaded applications only, with old C99 compilers, and in

Eduardo Bart 6 Apr 30, 2022
Mx - C++ coroutine await, yield, channels, i/o events (single header + link to boost)

mx C++11 coroutine await, yield, channels, i/o events (single header + link to boost). This was originally part of my c++ util library kit, but I'm se

Grady O'Connell 4 Sep 21, 2019
Coroutine - C++11 single .h asymmetric coroutine implementation via ucontext / fiber

C++11 single .h asymmetric coroutine implementation API in namespace coroutine: routine_t create(std::function<void()> f); void destroy(routine_t id);

null 379 Jun 30, 2022
Coro - Single-header library facilities for C++2a Coroutines

coro This is a collection of single-header library facilities for C++2a Coroutines. coro/include/ co_future.h Provides co_future<T>, which is like std

Arthur O'Dwyer 60 Jul 20, 2022
Xenium is a noninteractive protocol for producing and redeeming single-use claim codes

Xenium Xenium is a noninteractive protocol for producing and redeeming single-use claim codes. What this means in practice is that you can have a devi

Nick Johnson 30 Jun 23, 2022
A framework for decentralised production and redemption of single-use codes

Xenium Xenium is a noninteractive protocol for producing and redeeming single-use claim codes. What this means in practice is that you can have a devi

Nick Johnson 30 Jun 23, 2022
A General-purpose Parallel and Heterogeneous Task Programming System

Taskflow Taskflow helps you quickly write parallel and heterogeneous tasks programs in modern C++ Why Taskflow? Taskflow is faster, more expressive, a

Taskflow 7.1k Aug 16, 2022
C++React: A reactive programming library for C++11.

C++React is reactive programming library for C++14. It enables the declarative definition of data dependencies between state and event flows. Based on

Sebastian 953 Aug 2, 2022
:copyright: Concurrent Programming Library (Coroutine) for C11

libconcurrent tiny asymmetric-coroutine library. Description asymmetric-coroutine bidirectional communication by yield_value/resume_value native conte

sharow 350 Aug 4, 2022
Material for the UIBK Parallel Programming Lab (2021)

UIBK PS Parallel Systems (703078, 2021) This repository contains material required to complete exercises for the Parallel Programming lab in the 2021

null 12 May 6, 2022
Header-only library for multithreaded programming

CsLibGuarded Introduction The CsLibGuarded library is a standalone header only library for multithreaded programming. This library provides templated

CopperSpice 178 Jul 18, 2022